-
-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to close snackbars on click away #182
Comments
notistack doesn't close snackbars on <SnackbarProvider
ref={(ele) => { this.ref = ele; }}
onClose={(event, reason, key) => {
if (reason === 'clickaway') {
this.ref.closeSnackbar(key);
}
// ...
}} |
Inside the onClose method is it possible get the access to the snackbar properties? For example to avoid the clickaway handler if the snackbar is persistent. |
No but you can store the key of your persistent snackbar somewhere and decide if you want to close it or not by comparing the keys. An easier approach would be to pass your own key in enqueueSnackbar options. key: ‘persistent-someuniqueid’ And in onClose check if key This way you don’t have to bother storing keys of persistent snackbars. |
Thank you! I've chosen the second approach. |
Thanks for the help! Since we have access to the currently open snacks, we can just see if the one we are trying to close has Here is an example in typescript.
|
Hi, here is a working example for those using react functional components:
|
I would love to have a property I can pass to
SnackbarProvider
andenqueSnackbar
that would add a click away listener to the snackbar so it would auto dismiss upon the next user interactionThe text was updated successfully, but these errors were encountered: