[Snackbar] autoHideDuration doesn't treat null like the docs say
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 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 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 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…
@brunomonteirosud You have linked a different project.
@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 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;
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
You need to fork the project first.
🤦♂ my bad... Just opened the request: https://github.com/mui-org/material-ui/pull/16257