From 91f4a637cd22f4cb1647dde64c1bfcc4b76557be Mon Sep 17 00:00:00 2001 From: atomiks Date: Thu, 26 Dec 2024 18:19:39 +1100 Subject: [PATCH] Improve outside press event check --- packages/react/src/popover/root/usePopoverRoot.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/react/src/popover/root/usePopoverRoot.ts b/packages/react/src/popover/root/usePopoverRoot.ts index 5e67a20daf..f7cd2a1990 100644 --- a/packages/react/src/popover/root/usePopoverRoot.ts +++ b/packages/react/src/popover/root/usePopoverRoot.ts @@ -67,6 +67,8 @@ export function usePopoverRoot(params: usePopoverRoot.Parameters): usePopoverRoo const { mounted, setMounted, transitionStatus } = useTransitionStatus(open); + const { openMethod, triggerProps } = useOpenInteractionType(open); + useScrollLock(open && modal && backdropRendered, triggerElement); const setOpen = useEventCallback( @@ -146,17 +148,20 @@ export function usePopoverRoot(params: usePopoverRoot.Parameters): usePopoverRoo stickIfOpen: false, }); + let outsidePressEvent: 'mousedown' | undefined = + modal || backdropRendered ? 'mousedown' : undefined; + // For infotips (`openOnHover`), ensure another infotip can immediately open on tap + if (!backdropRendered && openOnHover && openMethod === 'touch') { + outsidePressEvent = undefined; + } const dismiss = useDismiss(context, { - // For infotips (`openOnHover`), ensure another infotip can immediately open on tap - outsidePressEvent: !openOnHover && (modal || backdropRendered) ? 'mousedown' : undefined, + outsidePressEvent, }); const role = useRole(context); const { getReferenceProps, getFloatingProps } = useInteractions([hover, click, dismiss, role]); - const { openMethod, triggerProps } = useOpenInteractionType(open); - return React.useMemo( () => ({ open,