diff --git a/frontend/src/ui/useFloatingMenu.js b/frontend/src/ui/useFloatingMenu.js index 02362d2..3140ba6 100644 --- a/frontend/src/ui/useFloatingMenu.js +++ b/frontend/src/ui/useFloatingMenu.js @@ -197,12 +197,22 @@ const useFloatingMenu = ({ return undefined; } + let ignoreFocusEvents = true; + const rafId = typeof window !== 'undefined' + ? window.requestAnimationFrame(() => { + ignoreFocusEvents = false; + }) + : null; + if (!anchorRef?.current) { close(); return undefined; } const handlePointer = (event) => { + if (event.type === 'focusin' && ignoreFocusEvents) { + return; + } const menu = menuRef.current; const anchor = anchorRef?.current; if ((anchor && anchor.contains(event.target)) || (menu && menu.contains(event.target))) { @@ -222,6 +232,9 @@ const useFloatingMenu = ({ document.addEventListener('focusin', handlePointer); document.addEventListener('keydown', handleKeyDown); return () => { + if (rafId != null) { + window.cancelAnimationFrame(rafId); + } document.removeEventListener('mousedown', handlePointer); document.removeEventListener('touchstart', handlePointer); document.removeEventListener('focusin', handlePointer);