Skip to content

Commit

Permalink
add overflow auto when using anchor
Browse files Browse the repository at this point in the history
We want to constrain the anchored element within the viewport (minus the
padding if there is some). But without an `overflow: auto`, it would
overflow and the `maxWidth` / `maxHeight` are a bit pointless.

Once you opt-in to `anchor`, then we have to provide styles anywhere.
This improves the UX.
  • Loading branch information
RobinMalfait committed Apr 25, 2024
1 parent 8c7cbb3 commit 42964ad
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions packages/@headlessui-react/src/internal/floating.tsx
Expand Up @@ -314,6 +314,7 @@ export function FloatingProvider({
sizeMiddleware({
apply({ availableWidth, availableHeight, elements }) {
Object.assign(elements.floating.style, {
overflow: 'auto',
maxWidth: `${availableWidth - padding}px`,
maxHeight: `${availableHeight - padding}px`,
})
Expand Down

0 comments on commit 42964ad

Please sign in to comment.