Skip to content

[context menu] Fix explicit collisionAvoidance with side: 'flip' not working - #3877

Merged
atomiks merged 3 commits into
mui:masterfrom
obeattie:menu-flip
Jan 27, 2026
Merged

atomiks merged 3 commits into
mui:masterfrom
obeattie:menu-flip

Conversation

@obeattie

Copy link
Copy Markdown
Contributor

When setting collisionAvoidance={{ side: 'flip' }} on a ContextMenu, the menu was not flipping to the opposite side when there wasn't enough space. Instead, it would shift position while remaining on the same side.

Fixes #3876

Root cause

The shiftCrossAxis parameter was unconditionally set to true for context menus, which disabled the main axis flip in useAnchorPositioning due to this condition:t

mainAxis: !shiftCrossAxis && collisionAvoidanceSide === 'flip',

Fix

Only enable shiftCrossAxis for context menus when the user hasn't explicitly requested flip behavior.

This preserves the default shift behavior for context menus (which makes sense when positioned against a mouse click point), while allowing flip to work when explicitly configured.

Test plan

  • Added test for collisionAvoidance={{ side: 'flip' }} on ContextMenu (previously failing, now passes)
  • Existing tests continue to pass

@obeattie
obeattie marked this pull request as ready for review January 27, 2026 15:14
@pkg-pr-new

pkg-pr-new Bot commented Jan 27, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@3877
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3877
    

commit: a48effb

@netlify

netlify Bot commented Jan 27, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit a48effb
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69792007523b640008d957ee
😎 Deploy Preview https://deploy-preview-3877--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@greptile-apps

greptile-apps Bot commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

Fixed a bug where ContextMenu components with collisionAvoidance={{ side: 'flip' }} were not flipping to the opposite side when space was insufficient. The fix conditionally disables shiftCrossAxis only when the user explicitly requests flip behavior, preserving the default shift behavior for context menus while allowing flip to work when configured.

  • Modified MenuPositioner.tsx to check if collisionAvoidance.side === 'flip' before enabling shiftCrossAxis
  • Added test coverage verifying that context menus flip to the top when anchored near the bottom with insufficient space

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is a minimal, well-targeted change that addresses a specific bug. The logic is sound - it only disables shiftCrossAxis when the user explicitly sets collisionAvoidance.side to 'flip', preserving default behavior while fixing the reported issue. The PR includes comprehensive test coverage that validates the fix.
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/menu/positioner/MenuPositioner.tsx Fixed context menu flip behavior by conditionally disabling shiftCrossAxis when user explicitly sets collisionAvoidance.side to 'flip'
packages/react/src/context-menu/root/ContextMenuRoot.test.tsx Added comprehensive test for flip collision avoidance behavior on context menus

@mui-bot

mui-bot commented Jan 27, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+32B(+0.01%) 🔺+19B(+0.01%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@atomiks atomiks added type: bug It doesn't behave as expected. component: context menu Changes related to the context menu component. labels Jan 27, 2026
@atomiks atomiks changed the title [context-menu] Fix collisionAvoidance side flip not working [context menu] Fix explicit collisionAvoidance with side: 'flip' not working Jan 27, 2026

@atomiks atomiks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @obeattie

@atomiks
atomiks merged commit e7355a2 into mui:master Jan 27, 2026
atomiks pushed a commit to atomiks/base-ui that referenced this pull request Jan 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: context menu Changes related to the context menu component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[context menu] collisionAvoidance { side: 'flip' } shifts menu instead of flipping sides

3 participants