There is no way to prevent a Snackbar from being hidden when clicking outside. Or maybe I miss something. onRequestClose tells:
The reason parameter can optionally be used to control the response to
onRequestClose, for example ignoringclickaway.
There is no doc regarding how to ignore such a clickaway. Is there?
AFAIU such a clickaway callback argument is just informative, am I right?
If so, my original feature description remains: be able to keep open a Snackbar even if the user clicks away.
OK, I'm afraid: If I set the onRequestClose prop, then the component is never hidden (unless I set its open prop to false). Is that the expected behavior?
Fine. If onRequestClose is set the app is responsible of closing the component by setting its open prop. I'd like it to be better explained in the doc, but this is my fault.
Closing.
I couldn't get this working with onRequestClose.
Instead I used ClickAwayListenerProps as so:
<MuiSnackbar
// ...
ClickAwayListenerProps={{ onClickAway: () => null }}
>
Here are the docs for ClickAwayListnerProps for reference.
I assume the API has changed over the years. The solution by @TimAstier worked for me.
The correct solution is to ignore the onClose event callback when reason === "clickaway" (since v1).
Most helpful comment
The correct solution is to ignore the
onCloseevent callback whenreason === "clickaway"(since v1).