Skip to content

Commit

Permalink
Improve outside press event check
Browse files Browse the repository at this point in the history
  • Loading branch information
atomiks committed Dec 26, 2024
1 parent 12399b1 commit 91f4a63
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/react/src/popover/root/usePopoverRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 91f4a63

Please sign in to comment.