diff options
| author | Fuwn <[email protected]> | 2024-02-03 00:11:37 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2024-02-03 00:11:37 -0800 |
| commit | 1dc5778c320b95465f21345694fb45a567fcd775 (patch) | |
| tree | d3c13fc5fa4cf1f814cf7e423f09da2d8cf30196 /src/lib | |
| parent | fix(tooltip): clean up (diff) | |
| download | due.moe-1dc5778c320b95465f21345694fb45a567fcd775.tar.xz due.moe-1dc5778c320b95465f21345694fb45a567fcd775.zip | |
feat(tooltip): visible state flags
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/Tooltip/tooltip.ts | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/lib/Tooltip/tooltip.ts b/src/lib/Tooltip/tooltip.ts index ca3c3570..7c8099e6 100644 --- a/src/lib/Tooltip/tooltip.ts +++ b/src/lib/Tooltip/tooltip.ts @@ -6,6 +6,7 @@ const tooltip = (element: HTMLElement) => { const debounceDelay = 100; let hideTimeout: number | null = null; let debounceTimer: number | null = null; + let visible = false; const createTooltip = () => { if (!tooltipDiv) { @@ -54,12 +55,17 @@ const tooltip = (element: HTMLElement) => { updateTooltipPosition(x, y); setTimeout(() => { - if (tooltipDiv) tooltipDiv.style.opacity = '1'; + if (tooltipDiv) { + visible = true; + tooltipDiv.style.opacity = '1'; + } }, 10); } }; const hideTooltip = () => { + if (!visible) return; + hideTimeout = window.setTimeout(() => { if (tooltipDiv) { tooltipDiv.style.opacity = '0'; @@ -67,7 +73,9 @@ const tooltip = (element: HTMLElement) => { setTimeout(() => { if (tooltipDiv) { document.body.removeChild(tooltipDiv); + tooltipDiv = null; + visible = false; } }, tooltipTransitionTime); } |