Skip to content

Commit

Permalink
Merge pull request #750 from intechstudio/DANIM1130/fix-tooltip-leak
Browse files Browse the repository at this point in the history
Add tooltip div release on destroy
  • Loading branch information
danim1130 authored Jun 14, 2024
2 parents 2edcc33 + b5bf944 commit 2eef93b
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions src/renderer/main/_actions/tooltip.ts
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();
};

0 comments on commit 2eef93b

Please sign in to comment.