diff --git a/CHANGELOG.md b/CHANGELOG.md index 2debe518..76b76261 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)
diff --git a/src/SnackbarProvider.js b/src/SnackbarProvider.js index 44c5ddd9..a9364087 100644 --- a/src/SnackbarProvider.js +++ b/src/SnackbarProvider.js @@ -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); }