mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
fix(toast-notification): fire on:clear
from timeout correctly
Fixes #1914 Co-Authored-By: brunnerh <brunnerh@users.noreply.github.com>
This commit is contained in:
parent
ced9673681
commit
9aabe3cbbb
1 changed files with 17 additions and 4 deletions
|
@ -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 },
|
||||
|
@ -66,14 +69,24 @@
|
|||
}
|
||||
|
||||
onMount(() => {
|
||||
if (timeout) {
|
||||
timeoutId = setTimeout(() => close(true), timeout);
|
||||
}
|
||||
|
||||
return () => {
|
||||
clearTimeout(timeoutId);
|
||||
};
|
||||
});
|
||||
|
||||
$: if (typeof window !== "undefined") {
|
||||
/**
|
||||
* Clear the timer if {@link timeout} changes.
|
||||
* If set to `0`, no new timeout is started.
|
||||
* Else, a new timeout is started if {@link open} is not set to `false`.
|
||||
*/
|
||||
clearTimeout(timeoutId);
|
||||
|
||||
/** 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 -->
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue