Skip to content

Commit

Permalink
fix(overflowmenu): improve autoAlign fallback placements (#17248)
Browse files Browse the repository at this point in the history
  • Loading branch information
tay1orjones authored Aug 23, 2024
1 parent 95adfbb commit dbe4f28
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/react/src/components/OverflowMenu/next/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,27 @@ const OverflowMenu = React.forwardRef<HTMLDivElement, OverflowMenuProps>(
const { refs, floatingStyles, placement, middlewareData } = useFloating(
autoAlign
? {
// Computing the position starts with initial positioning
// via `placement`.
placement: menuAlignment,

// The floating element is positioned relative to its nearest
// containing block (usually the viewport). It will in many cases also
// “break” the floating element out of a clipping ancestor.
// containing block (usually the viewport). It will in many cases
// also “break” the floating element out of a clipping ancestor.
// https://floating-ui.com/docs/misc#clipping
strategy: 'fixed',

// Middleware order matters, arrow should be last
// Middleware are executed as an in-between “middle” step of the
// initial `placement` computation and eventual return of data for
// rendering. Each middleware is executed in order.
middleware: [
flip({
fallbackAxisSideDirection: 'start',
fallbackPlacements: [
'top-start',
'top-end',
'bottom-start',
'bottom-end',
],
// An explicit array of placements to try if the initial
// `placement` doesn’t fit on the axes in which overflow
// is checked.
fallbackPlacements: menuAlignment.includes('bottom')
? ['bottom-start', 'bottom-end', 'top-start', 'top-end']
: ['top-start', 'top-end', 'bottom-start', 'bottom-end'],
}),
],
whileElementsMounted: autoUpdate,
Expand Down

0 comments on commit dbe4f28

Please sign in to comment.