generated from sarioglu/svelte-tailwindcss-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #750 from intechstudio/DANIM1130/fix-tooltip-leak
Add tooltip div release on destroy
- Loading branch information
Showing
1 changed file
with
19 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,33 @@ | ||
import { MoltenTooltip } from "@intechstudio/grid-uikit"; | ||
import { tooltip_content } from "../user-interface/tooltip/tooltip-content.json"; | ||
import type { Action } from "svelte/action"; | ||
|
||
export const tooltip: Action<HTMLElement, any> = ( | ||
node: HTMLElement, | ||
options: any | ||
): void => { | ||
): any => { | ||
if (typeof options === "undefined") { | ||
return; | ||
} | ||
|
||
const setTooltipAsync = async () => { | ||
let text: string = ""; | ||
if (typeof options.key !== "undefined") { | ||
text = tooltip_content[options.key]; | ||
} else if (typeof options.text !== "undefined") { | ||
text = options.text; | ||
} | ||
const sibling = document.createElement("div"); | ||
node.parentNode?.insertBefore(sibling, node.nextSibling); | ||
|
||
const MoltenTooltip = (await import("@intechstudio/grid-uikit")) | ||
.MoltenTooltip; | ||
let text: string = ""; | ||
if (typeof options.key !== "undefined") { | ||
text = tooltip_content[options.key]; | ||
} else if (typeof options.text !== "undefined") { | ||
text = options.text; | ||
} | ||
const sibling = document.createElement("div"); | ||
node.parentNode?.insertBefore(sibling, node.nextSibling); | ||
|
||
options.referenceElement = node; | ||
options.text = text; | ||
options.referenceElement = node; | ||
options.text = text; | ||
|
||
new MoltenTooltip({ | ||
target: sibling, | ||
props: options, | ||
}); | ||
setTimeout(() => { | ||
new MoltenTooltip({ target: sibling, props: options }); | ||
}); | ||
return { | ||
destroy() { | ||
sibling.remove(); | ||
}, | ||
}; | ||
setTooltipAsync(); | ||
}; |