Skip to content
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

The callback of onClose can be executed when you click any way #220

Closed
dgczhh opened this issue Jan 24, 2020 · 3 comments
Closed

The callback of onClose can be executed when you click any way #220

dgczhh opened this issue Jan 24, 2020 · 3 comments

Comments

@dgczhh
Copy link

dgczhh commented Jan 24, 2020

I have two problems on notistack.
First, I set up the callback of onClose on a snackbar and show it, the callback will be executed when I click any way.
Second, when I add a close button on snackbar to close it manually,the callback of onClose will not be executed.
I fixed the two problem temporarily by adding some code to the source code of SnackbarItem.js and SnackbarProvider.js.

Expected Behavior

When I click any way ,the callback of onClose on a snackbar can't be executed.
When I close a snackbar manually, the callback of onClose on a snackbar can be executed.

Current Behavior

Contrary to the Expected Behavior.

Steps to Reproduce

Link: https://github.com/dgczhh/notistackdemo
1.npm install
2.npm start
3.open the Chrome DevTools
4.click the button in web and check the output

Context

I fixed the first problem temporarily by adding some code to node_modules\notistack\build\SnackbarItem\SnackbarItem.js after line 78:

if(reason === _constants.REASONS.CLICKAWAY) {
     return;
}

I fixed the second problem temporarily by adding some code to node_modules\notistack\build\SnackbarProvider.js after line 217:

  if(item.key === key) {
         if(reason === null) {
                 if(item.onClose) {
                          item.onClose()
                  }
          }
     }

Your Environment

Tech Version
Notistack ^0.9.7
React ^16.12.0
Browser Chrome 79.03945.130
etc.
@iamhosseindhv
Copy link
Owner

Regarding your first problem, it's not really a problem, but expected behaviour. Notistack also does nothing on clickaway event:

if (reason === REASONS.CLICKAWAY) return;

You can add this to your onClose callbacks too.

Second problem, you're right. when a snackbar is closed using closeSnackbar method, onClose callback passed in options parameter of enqueueSnackbar does not get called.

@iamhosseindhv
Copy link
Owner

Fix will be published in v0.9.8

@dgczhh
Copy link
Author

dgczhh commented Jan 27, 2020

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants