mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 19:46:36 +00:00
onDestroy
we want to remove the event listener
to prevent listeners hanging
This commit is contained in:
parent
c421bea06e
commit
98327385fd
1 changed files with 7 additions and 1 deletions
|
@ -98,7 +98,7 @@
|
||||||
/** Obtain a reference to the button HTML element */
|
/** Obtain a reference to the button HTML element */
|
||||||
export let ref = null;
|
export let ref = null;
|
||||||
|
|
||||||
import { createEventDispatcher, onMount } from "svelte";
|
import { createEventDispatcher, onDestroy, onMount } from "svelte";
|
||||||
import WarningFilled from "../icons/WarningFilled.svelte";
|
import WarningFilled from "../icons/WarningFilled.svelte";
|
||||||
import WarningAltFilled from "../icons/WarningAltFilled.svelte";
|
import WarningAltFilled from "../icons/WarningAltFilled.svelte";
|
||||||
import {
|
import {
|
||||||
|
@ -160,6 +160,12 @@
|
||||||
parent.addEventListener("click", pageClickHandler);
|
parent.addEventListener("click", pageClickHandler);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onDestroy(() => {
|
||||||
|
if (parent) {
|
||||||
|
parent.removeEventListener("click", pageClickHandler);
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window on:click="{pageClickHandler}" />
|
<svelte:window on:click="{pageClickHandler}" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue