diff --git a/.changeset/olive-drinks-float.md b/.changeset/olive-drinks-float.md new file mode 100644 index 0000000000..6f58a5cbbc --- /dev/null +++ b/.changeset/olive-drinks-float.md @@ -0,0 +1,5 @@ +--- +"@heroui/use-aria-overlay": patch +--- + +sync with RA useOverlay hook (#5500) diff --git a/packages/hooks/use-aria-overlay/src/index.ts b/packages/hooks/use-aria-overlay/src/index.ts index 9edf10b904..09c53333f9 100644 --- a/packages/hooks/use-aria-overlay/src/index.ts +++ b/packages/hooks/use-aria-overlay/src/index.ts @@ -37,17 +37,17 @@ export function useAriaOverlay(props: UseAriaOverlayProps, ref: RefObject { - 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 @@ -65,19 +65,11 @@ export function useAriaOverlay(props: UseAriaOverlayProps, ref: RefObject { - 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