[Snackbar] resumeHideDuration short-circuits on 0 milliseconds #11946
Labels
bug 🐛
Something doesn't work
component: snackbar
This is the name of the generic UI component, not the React module!
good first issue
Great for first contributions. Enable to learn the contribution process.
Expected Behavior
When passing a value of
0
into the resumeHideDuration prop of the Snackbar component, the Snackbar will immediately fireonClose
following a user interaction.Current Behavior
When passing a value of
0
into the resumeHideDuration prop of the Snackbar component, the component uses the autoHideDuration prop instead, because the value of0
evaluates tofalse
in short-circuit evaluationI can confirm this by looking at the source code of the Snackbar component. On Line 182 the component attempts to set a timer using the resumeHideDuration prop
https://github.com/mui-org/material-ui/blob/dce7801ffc1187137301d84bc367e7b8880e522e/packages/material-ui/src/Snackbar/Snackbar.js#L182
Then on Line 146, any value that evaluates to false will be skipped, with the next option being to use this.props.autoHideDuration.
https://github.com/mui-org/material-ui/blob/dce7801ffc1187137301d84bc367e7b8880e522e/packages/material-ui/src/Snackbar/Snackbar.js#L133-L147
Steps to Reproduce
Create
<Snackbar />
component providing proper state handling of the open & onClose props, also supplying an action prop, allowing for user interaction. Then supply an autoHideDuration prop of any number larger than 0, and a resumeHideDuration prop with the value of 0.Activate the snackbar
Interact with the snackbar (ie. click the Undo button)
CodeSandbox: https://codesandbox.io/s/04nz3r87qn
Your Environment
The text was updated successfully, but these errors were encountered: