This commit is contained in:
2025-11-10 12:14:40 +01:00
parent 218f2f2475
commit 288c53364e
+13
View File
@@ -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);