Skip to content

Commit dbe4f28

Browse files
authored
fix(overflowmenu): improve autoAlign fallback placements (#17248)
1 parent 95adfbb commit dbe4f28

File tree

1 file changed

+13
-10
lines changed
  • packages/react/src/components/OverflowMenu/next

1 file changed

+13
-10
lines changed

packages/react/src/components/OverflowMenu/next/index.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,24 +94,27 @@ const OverflowMenu = React.forwardRef<HTMLDivElement, OverflowMenuProps>(
9494
const { refs, floatingStyles, placement, middlewareData } = useFloating(
9595
autoAlign
9696
? {
97+
// Computing the position starts with initial positioning
98+
// via `placement`.
9799
placement: menuAlignment,
98100

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

105-
// Middleware order matters, arrow should be last
107+
// Middleware are executed as an in-between “middle” step of the
108+
// initial `placement` computation and eventual return of data for
109+
// rendering. Each middleware is executed in order.
106110
middleware: [
107111
flip({
108-
fallbackAxisSideDirection: 'start',
109-
fallbackPlacements: [
110-
'top-start',
111-
'top-end',
112-
'bottom-start',
113-
'bottom-end',
114-
],
112+
// An explicit array of placements to try if the initial
113+
// `placement` doesn’t fit on the axes in which overflow
114+
// is checked.
115+
fallbackPlacements: menuAlignment.includes('bottom')
116+
? ['bottom-start', 'bottom-end', 'top-start', 'top-end']
117+
: ['top-start', 'top-end', 'bottom-start', 'bottom-end'],
115118
}),
116119
],
117120
whileElementsMounted: autoUpdate,

0 commit comments

Comments
 (0)