mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
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:
parent
36eb421c66
commit
8dc4bab4ec
5
.changeset/olive-drinks-float.md
Normal file
5
.changeset/olive-drinks-float.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@heroui/use-aria-overlay": patch
|
||||
---
|
||||
|
||||
sync with RA useOverlay hook (#5500)
|
||||
@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user