Skip to content

Commit

Permalink
Fixes #220 - fix bug with onClose callback on individual snackbar
Browse files Browse the repository at this point in the history
  • Loading branch information
iamhosseindhv committed Jan 27, 2020
1 parent 38f598c commit d22ae1e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Thanks to all contributers who improved notistack by opening an issue/PR.
* **@david-chau**: Allow `asc`, `desc` or custom sort order of snackbars [#160](https://github.com/iamhosseindhv/notistack/issues/160)
* **@madaz**: Add higher priority to Snackbar styles [#202](https://github.com/iamhosseindhv/notistack/issues/202)
* **@svish**: Correct enqueueSnackbar typing [#217](https://github.com/iamhosseindhv/notistack/issues/217)
* **@dgczhh**: Make sure `onClose` callback that's been passed through options parameter of `enqueueSnackbar` gets called when snackbar is closed using `closeSnackbar` function [#220](https://github.com/iamhosseindhv/notistack/issues/220)


<br />
Expand Down
6 changes: 6 additions & 0 deletions src/SnackbarProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ class SnackbarProvider extends Component {
* @param {number} key - id of the snackbar we want to hide
*/
closeSnackbar = (key) => {
// call individual snackbar onClose callback passed through options parameter
const toBeClosed = this.state.snacks.find(item => item.key === key);
if (toBeClosed && toBeClosed.onClose) {
toBeClosed.onClose(null, null, key);
}

this.handleCloseSnack(null, null, key);
}

Expand Down

0 comments on commit d22ae1e

Please sign in to comment.