Properly dispose of tooltip resources when unmounting

This commit is contained in:
Henrik Giesel 2021-06-12 00:54:20 +02:00
parent 97692e4c28
commit 9a00ef5a81

View file

@ -3,19 +3,28 @@
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import { onDestroy } from "svelte";
import Tooltip from "bootstrap/js/dist/tooltip"; import Tooltip from "bootstrap/js/dist/tooltip";
export let tooltip: string; export let tooltip: string;
let tooltipObject: Tooltip;
function createTooltip(element: HTMLElement): void { function createTooltip(element: HTMLElement): void {
element.title = tooltip; element.title = tooltip;
new Tooltip(element, { tooltipObject = new Tooltip(element, {
placement: "bottom", placement: "bottom",
html: true, html: true,
offset: [0, 20], offset: [0, 20],
delay: { show: 250, hide: 0 }, delay: { show: 250, hide: 0 },
}); });
} }
onDestroy(() => {
if (tooltipObject) {
tooltipObject.dispose();
}
});
</script> </script>
<slot {createTooltip} /> <slot {createTooltip} />