fix
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user