From 1dc5778c320b95465f21345694fb45a567fcd775 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 3 Feb 2024 00:11:37 -0800 Subject: feat(tooltip): visible state flags --- src/lib/Tooltip/tooltip.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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); } -- cgit v1.2.3