mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
fix: clear timeout in onMount return function
This commit is contained in:
parent
bd6bd15c79
commit
fff54a19eb
3 changed files with 23 additions and 21 deletions
|
@ -3,15 +3,17 @@
|
|||
export let feedbackTimeout = 2000;
|
||||
export let ref = null;
|
||||
|
||||
import { onDestroy } from "svelte";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
$: animation = undefined;
|
||||
$: timeoutId = undefined;
|
||||
$: showFeedback = timeoutId !== undefined;
|
||||
let animation = undefined;
|
||||
let timeout = undefined;
|
||||
|
||||
onDestroy(() => {
|
||||
window.clearTimeout(timeoutId);
|
||||
timeoutId = undefined;
|
||||
$: showFeedback = timeout !== undefined;
|
||||
|
||||
onMount(() => {
|
||||
return () => {
|
||||
clearTimeout(timeout);
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
|
@ -29,7 +31,7 @@
|
|||
on:click={() => {
|
||||
if (animation === 'fade-in') return;
|
||||
animation = 'fade-in';
|
||||
timeoutId = setTimeout(() => {
|
||||
timeout = setTimeout(() => {
|
||||
animation = 'fade-out';
|
||||
}, feedbackTimeout);
|
||||
}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue