Skip to content

Commit

Permalink
fix(toast-notification): clear autoclose timeout correctly
Browse files Browse the repository at this point in the history
Fixes #1914
  • Loading branch information
metonym committed Feb 24, 2024
1 parent 0c99e05 commit 5e22a38
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Notification/ToastNotification.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
let timeoutId = undefined;
function close(closeFromTimeout) {
// Clear the timer if the close button was clicked.
clearTimeout(timeoutId);
const shouldContinue = dispatch(
"close",
{ timeout: closeFromTimeout === true },
Expand All @@ -66,14 +69,17 @@
}
onMount(() => {
if (timeout) {
timeoutId = setTimeout(() => close(true), timeout);
}
return () => {
clearTimeout(timeoutId);
};
});
$: if (typeof window !== "undefined") {
/** Only start the timer of {@link open} has not been set to `false`. */
if (open && timeout) {
timeoutId = setTimeout(() => close(true), timeout);
}
}
</script>

<!-- svelte-ignore a11y-mouse-events-have-key-events -->
Expand Down

0 comments on commit 5e22a38

Please sign in to comment.