Skip to content

Commit

Permalink
fix(Popper): use visibility to hide instead of opacity (#2744)
Browse files Browse the repository at this point in the history
* fix(Popper): use `visibility` to hide instead of `opacity`

When using `hideWhenDetached`, the opacity is changed to 0 instead of the
visibility. This lets users click items that they cannot see. This is
generally a bad user experience.

This patch updates the `Popper` to set the `visibility` to `hidden` when
`hideWhenDetached` is used. This ensures the user cannot interact with
the hidden element.

This aligns with what is in the `@floating-ui/react-dom` documentation.

Ref: https://floating-ui.com/docs/hide#usage

Closes: #2743

* Update packages/react/popper/src/Popper.tsx

* Create 5793010b.yml

---------

Co-authored-by: Benoît Grélard <benoit.grelard@gmail.com>
  • Loading branch information
nicholaschiang and benoitgrelard authored Feb 29, 2024
1 parent ef4cc7d commit e5ba0d9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .yarn/versions/5793010b.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
2 changes: 1 addition & 1 deletion packages/react/popper/src/Popper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ const PopperContent = React.forwardRef<PopperContentElement, PopperContentProps>
// 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
opacity: middlewareData.hide?.referenceHidden ? 0 : undefined,
visibility: middlewareData.hide?.referenceHidden ? 'hidden' : undefined,
}}
/>
</PopperContentProvider>
Expand Down

0 comments on commit e5ba0d9

Please sign in to comment.