Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/olive-drinks-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@heroui/use-aria-overlay": patch
---

sync with RA useOverlay hook (#5500)
27 changes: 9 additions & 18 deletions packages/hooks/use-aria-overlay/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ export function useAriaOverlay(props: UseAriaOverlayProps, ref: RefObject<Elemen

// Add the overlay ref to the stack of visible overlays on mount, and remove on unmount.
useEffect(() => {
if (isOpen) {
if (isOpen && !visibleOverlays.includes(ref)) {
visibleOverlays.push(ref);
}

return () => {
const index = visibleOverlays.indexOf(ref);
return () => {
let index = visibleOverlays.indexOf(ref);

if (index >= 0) {
visibleOverlays.splice(index, 1);
}
};
if (index >= 0) {
visibleOverlays.splice(index, 1);
}
};
}
}, [isOpen, ref]);

// Only hide the overlay when it is the topmost visible overlay in the stack
Expand All @@ -65,27 +65,18 @@ export function useAriaOverlay(props: UseAriaOverlayProps, ref: RefObject<Elemen
e.preventDefault();
}
}

// For consistency with React Aria, toggle the combobox/menu on mouse down, but touch up.
if (e.pointerType !== "touch") {
onHide();
}
onHide();
}
};

const onInteractOutside = (e: PointerEvent) => {
if (e.pointerType !== "touch") {
return;
}

if (!shouldCloseOnInteractOutside || shouldCloseOnInteractOutside(e.target as Element)) {
if (visibleOverlays[visibleOverlays.length - 1] === ref) {
if (disableOutsideEvents) {
e.stopPropagation();
e.preventDefault();
}
}

onHide();
}
};
Expand Down