mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
feat(toast-notification): clear timeout when destroyed
This commit is contained in:
parent
41c096bada
commit
7a612e60cf
1 changed files with 7 additions and 1 deletions
|
@ -21,14 +21,20 @@
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
let timeoutId = undefined;
|
||||||
let open = true;
|
let open = true;
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
window.setTimeout(() => {
|
timeoutId = window.setTimeout(() => {
|
||||||
open = false;
|
open = false;
|
||||||
}, timeout);
|
}, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.clearTimeout(timeoutId);
|
||||||
|
timeoutId = undefined;
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
$: if (!open) {
|
$: if (!open) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue