From 057f9b9bdbcaeca35267fa4d0c1876e5ad45e83c Mon Sep 17 00:00:00 2001 From: metonym Date: Wed, 29 Jun 2022 11:07:02 -0700 Subject: [PATCH] Revert "Revert "fix(notification): `on:close` should be cancellable (#1379)" (#1381)" This reverts commit 052acfc2cebb1c011046f253d97748a720af4e45. --- src/Notification/InlineNotification.svelte | 10 ++++++++-- src/Notification/ToastNotification.svelte | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Notification/InlineNotification.svelte b/src/Notification/InlineNotification.svelte index 19cb0588..4cd57717 100644 --- a/src/Notification/InlineNotification.svelte +++ b/src/Notification/InlineNotification.svelte @@ -40,8 +40,14 @@ let timeoutId = undefined; function close(closeFromTimeout) { - open = false; - dispatch("close", { timeout: closeFromTimeout === true }); + const shouldContinue = dispatch( + "close", + { timeout: closeFromTimeout === true }, + { cancelable: true } + ); + if (shouldContinue) { + open = false; + } } onMount(() => { diff --git a/src/Notification/ToastNotification.svelte b/src/Notification/ToastNotification.svelte index ff60b6c7..1d00ba4e 100644 --- a/src/Notification/ToastNotification.svelte +++ b/src/Notification/ToastNotification.svelte @@ -43,8 +43,14 @@ let timeoutId = undefined; function close(closeFromTimeout) { - open = false; - dispatch("close", { timeout: closeFromTimeout === true }); + const shouldContinue = dispatch( + "close", + { timeout: closeFromTimeout === true }, + { cancelable: true } + ); + if (shouldContinue) { + open = false; + } } onMount(() => {