Material-ui: Avoid Snackbar to be hidden on external click

Created on 14 Sep 2016  路  6Comments  路  Source: mui-org/material-ui

Description

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 ignoring clickaway.

There is no doc regarding how to ignore such a clickaway. Is there?

Snackbar question

Most helpful comment

The correct solution is to ignore the onClose event callback when reason === "clickaway" (since v1).

All 6 comments

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).

Was this page helpful?
0 / 5 - 0 ratings