From e00fdc2d5986b3f12b93e410ae7e191da8fe5315 Mon Sep 17 00:00:00 2001 From: YAVIIGI <118232419+YAVIIGI@users.noreply.github.com> Date: Tue, 3 Oct 2023 11:27:51 +0900 Subject: fix(frontend): use-tooltip の呼び出し元の UI が無くなったら自動的に削除されるようにする (#11949) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update use-tooltip.ts * Update CHANGELOG.md --- packages/frontend/src/scripts/use-tooltip.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'packages/frontend/src/scripts/use-tooltip.ts') diff --git a/packages/frontend/src/scripts/use-tooltip.ts b/packages/frontend/src/scripts/use-tooltip.ts index 0a82997728..17ea380db0 100644 --- a/packages/frontend/src/scripts/use-tooltip.ts +++ b/packages/frontend/src/scripts/use-tooltip.ts @@ -21,6 +21,8 @@ export function useTooltip( let changeShowingState: (() => void) | null; + let autoHidingTimer; + const open = () => { close(); if (!isHovering) return; @@ -33,6 +35,16 @@ export function useTooltip( changeShowingState = () => { showing.value = false; }; + + autoHidingTimer = window.setInterval(() => { + if (!document.body.contains(elRef.value)) { + if (!isHovering) return; + isHovering = false; + window.clearTimeout(timeoutId); + close(); + window.clearInterval(autoHidingTimer); + } + }, 1000); }; const close = () => { @@ -53,6 +65,7 @@ export function useTooltip( if (!isHovering) return; isHovering = false; window.clearTimeout(timeoutId); + window.clearInterval(autoHidingTimer); close(); }; @@ -67,6 +80,7 @@ export function useTooltip( if (!isHovering) return; isHovering = false; window.clearTimeout(timeoutId); + window.clearInterval(autoHidingTimer); close(); }; -- cgit v1.2.3-freya