Skip to content

Commit

Permalink
fix(Popper): disable pointer events when hidden (radix-ui#2745)
Browse files Browse the repository at this point in the history
* fix(Popper): disable pointer events when hidden

This patch sets `pointer-events: none` when the `<PopperContent>` is
hidden so that the UI behaves as if it is not there at all. This ensures
that users can interact with elements beneath the `<PopperContent>`
uninterrupted.

Ref: radix-ui#2743 (comment)

Fixes: e5ba0d9 ("fix(Popper): use `visibility` to hide instead of `opacity` (radix-ui#2744)")

* Move to wrapper

---------

Co-authored-by: Benoît Grélard <[email protected]>
  • Loading branch information
nicholaschiang and benoitgrelard authored Mar 1, 2024
1 parent 8b1162c commit f58a28c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
13 changes: 13 additions & 0 deletions .yarn/versions/dc4b1017.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
releases:
"@radix-ui/react-context-menu": patch
"@radix-ui/react-dropdown-menu": patch
"@radix-ui/react-hover-card": patch
"@radix-ui/react-menu": patch
"@radix-ui/react-menubar": patch
"@radix-ui/react-popover": patch
"@radix-ui/react-popper": patch
"@radix-ui/react-select": patch
"@radix-ui/react-tooltip": patch

declined:
- primitives
10 changes: 8 additions & 2 deletions packages/react/popper/src/Popper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ const PopperContent = React.forwardRef<PopperContentElement, PopperContentProps>
middlewareData.transformOrigin?.x,
middlewareData.transformOrigin?.y,
].join(' '),

// hide the content if using the hide middleware and should be hidden
// set visibility to hidden and disable pointer events so the UI behaves
// as if the PopperContent isn't there at all
...(middlewareData.hide?.referenceHidden && {
visibility: 'hidden',
pointerEvents: 'none',
}),
}}
// Floating UI interally calculates logical alignment based the `dir` attribute on
// the reference/floating node, we must add this attribute here to ensure
Expand All @@ -267,8 +275,6 @@ const PopperContent = React.forwardRef<PopperContentElement, PopperContentProps>
// if the PopperContent hasn't been placed yet (not all measurements done)
// we prevent animations so that users's animation don't kick in too early referring wrong sides
animation: !isPositioned ? 'none' : undefined,
// hide the content if using the hide middleware and should be hidden
visibility: middlewareData.hide?.referenceHidden ? 'hidden' : undefined,
}}
/>
</PopperContentProvider>
Expand Down

0 comments on commit f58a28c

Please sign in to comment.