Skip to content

Commit

Permalink
make sure a toast has not already been dismissed when dismissing it (e…
Browse files Browse the repository at this point in the history
…lastic#868)

* make sure a toast has not already been dismissed when dismissing it

* changelog
  • Loading branch information
chandlerprall committed May 24, 2018
1 parent 4cd0b09 commit 7d9c1f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- `EuiButton`, `EuiButtonEmpty`, and `EuiButtonIcon` now look and behave disabled when `isDisabled={true}` ([#862](https://github.com/elastic/eui/pull/862))
- `EuiGlobalToastList` no longer triggers `Uncaught TypeError: _this.callback is not a function` ([#865](https://github.com/elastic/eui/pull/865))
- `EuiGlobalToastList` checks to see if it has dismissed a toast before re-dismissing it ([#868](https://github.com/elastic/eui/pull/868))

## [`0.0.49`](https://github.com/elastic/eui/tree/v0.0.49)

Expand Down
30 changes: 18 additions & 12 deletions src/components/toast/global_toast_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,24 @@ export class EuiGlobalToastList extends Component {
dismissToast = (toast) => {
// Remove the toast after it's done fading out.
this.dismissTimeoutIds.push(setTimeout(() => {
this.props.dismissToast(toast);
this.toastIdToTimerMap[toast.id].clear();
delete this.toastIdToTimerMap[toast.id];

this.setState(prevState => {
const toastIdToDismissedMap = { ...prevState.toastIdToDismissedMap };
delete toastIdToDismissedMap[toast.id];

return {
toastIdToDismissedMap,
};
});
// Because this is wrapped in a setTimeout, and because React does not guarantee when
// state updates happen, it is possible to double-dismiss a toast
// including by double-clicking the "x" button on the toast
// so, first check to make sure we haven't already dismissed this toast
if (this.toastIdToTimerMap.hasOwnProperty(toast.id)) {
this.props.dismissToast(toast);
this.toastIdToTimerMap[toast.id].clear();
delete this.toastIdToTimerMap[toast.id];

this.setState(prevState => {
const toastIdToDismissedMap = { ...prevState.toastIdToDismissedMap };
delete toastIdToDismissedMap[toast.id];

return {
toastIdToDismissedMap,
};
});
}
}, TOAST_FADE_OUT_MS));

this.setState(prevState => {
Expand Down

0 comments on commit 7d9c1f8

Please sign in to comment.