fix(use-aria-overlay): sync with RA's overlay logic (#5529)

* fix(use-aria-overlay): sync with RA logic

* fix(use-aria-overlay): add onHide on onInteractOutsideStart

* chore(changeset): add changeset
This commit is contained in:
WK 2025-07-29 00:52:21 +08:00 committed by GitHub
parent 36eb421c66
commit 8dc4bab4ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 19 deletions

View File

@ -0,0 +1,5 @@
---
"@heroui/use-aria-overlay": patch
---
sync with RA useOverlay hook (#5500)

View File

@ -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 () => {
let index = visibleOverlays.indexOf(ref);
if (index >= 0) {
visibleOverlays.splice(index, 1);
}
};
}
return () => {
const index = visibleOverlays.indexOf(ref);
if (index >= 0) {
visibleOverlays.splice(index, 1);
}
};
}, [isOpen, ref]);
// Only hide the overlay when it is the topmost visible overlay in the stack
@ -65,19 +65,11 @@ 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) {
@ -85,7 +77,6 @@ export function useAriaOverlay(props: UseAriaOverlayProps, ref: RefObject<Elemen
e.preventDefault();
}
}
onHide();
}
};