material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[Snackbar] autoHideDuration doesn't treat null like the docs say

Open hoolymama opened this issue 9 years ago • 9 comments

In 1.0.0-beta.20 If I set autoHideDuration={null}, onRequestClose() is triggered immediately as if the value is 0

  • [x ] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

The docs say autoHideDuration will be disabled if set to null

Current Behavior

Currently null is treated like 0, however I can set it to undefined and it works like it used to.

I want to keep the snackbar visible indefinitely only if there are more details (accessed through a link in the snnackbar), so code looks something like this:

<Snackbar
      onRequestClose={onDismiss}
      autoHideDuration={hasMoreDetails ? null : 4000}
      action={[ renderDetailsButton(hasMoreDetails),     <CloseButton />    ]}
/>

The workaround is fine

autoHideDuration={hasMoreDetails ? undefined : 4000}

.. but then the docs need updating

Your Environment

Tech Version
Material-UI 1.0.0-beta.20
React 15.6.2
browser chrome

hoolymama avatar Nov 10 '17 20:11 hoolymama

@hoolymama The behavior was changed in https://github.com/callemall/material-ui/pull/8448/files#diff-c54f3a36461afdc2f6227a9ca87424a4L252. I can't remember the motivation for such change. Also, this change wasn't documented as a breaking change. As far as I know, It shouldn't have been changed. What do you think of putting the null logic back? Do you want to take care of it?

oliviertassinari avatar Nov 10 '17 20:11 oliviertassinari

@oliviertassinari I think the logic is fine as it is so long as the docs say the same thing. Semantically, I guess null is slightly better in cases where you need to have the prop present and assign something, like my example. I'm happy to change it back if you like.

hoolymama avatar Nov 10 '17 22:11 hoolymama

@hoolymama Sorry, didn't want to take away your work :see_no_evil: I was just thinking that this might need a test, so I added a test and ended up changing it back right away…

leMaik avatar Nov 10 '17 23:11 leMaik

@brunomonteirosud You have linked a different project.

oliviertassinari avatar Jun 14 '19 06:06 oliviertassinari

@oliviertassinari Oops, my bad. Not sure how I got that 😅 Anyway, I am trying to achieve the same behaviour above, and I got a type error:

Type null is not assignable to type number

So I was confused if this changed was implemented or not...

brunomonteirosud avatar Jun 14 '19 09:06 brunomonteirosud

@brunomonteirosud Thank you for the report. It's a bug with our TypeScript definitions. Do you want to submit a pull request with this fix :)?

diff --git a/packages/material-ui/src/Snackbar/Snackbar.d.ts b/packages/material-ui/src/Snackbar/Snackbar.d.ts
index 9a2a3e896..f0535fd15 100644
--- a/packages/material-ui/src/Snackbar/Snackbar.d.ts
+++ b/packages/material-ui/src/Snackbar/Snackbar.d.ts
@@ -16,7 +16,7 @@ export interface SnackbarProps
   > {
   action?: SnackbarContentProps['action'];
   anchorOrigin?: SnackbarOrigin;
-  autoHideDuration?: number;
+  autoHideDuration?: number | null;
   ClickAwayListenerProps?: Partial<ClickAwayListenerProps>;
   ContentProps?: Partial<SnackbarContentProps>;
   disableWindowBlurListener?: boolean;

oliviertassinari avatar Jun 15 '19 10:06 oliviertassinari

Sure, happy to do it! I am pretty new to this process of contributing...I tried to follow the instructions from this link but wasn't able to checkout the project. Is git clone [email protected]:brunomonteirosud/material-ui.git the correct path? Do you need to authorize me first? Thanks

brunomonteirosud avatar Jun 16 '19 00:06 brunomonteirosud

You need to fork the project first.

oliviertassinari avatar Jun 16 '19 08:06 oliviertassinari

🤦‍♂ my bad... Just opened the request: https://github.com/mui-org/material-ui/pull/16257

brunomonteirosud avatar Jun 16 '19 21:06 brunomonteirosud