[context menu] Fix disabled prop not working#3806
Conversation
commit: |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Greptile SummaryFixed
Issue found: The Confidence Score: 3/5
Important Files Changed
|
There was a problem hiding this comment.
Additional Comments (1)
-
packages/react/src/context-menu/trigger/ContextMenuTrigger.tsx, line 154-172 (link)logic: Native context menu still blocked when disabled.
When disabled, the native browser context menu won't appear on the trigger element. The
handleDocumentContextMenueffect should checkdisabledstate before preventing default.
4 files reviewed, 1 comment
mj12albert
left a comment
There was a problem hiding this comment.
Thanks for the PR ~ I can reproduce the bug and left some comments
packages/react/src/context-menu/trigger/ContextMenuTrigger.test.tsx
Outdated
Show resolved
Hide resolved
| import { Popover } from '@base-ui/react/popover'; | ||
|
|
||
| export default function ContextMenuExperiment() { | ||
| const [disabled, setDisabled] = React.useState(false); |
There was a problem hiding this comment.
For this it would be good to use
import {
SettingsMetadata,
useExperimentSettings,
} from '../../../components/Experiments/SettingsPanel'example:
There was a problem hiding this comment.
Not sure if its the right approach in this case. There's bunch of complex examples of the context-menu on this page like multi level nested context menus, and its not clear where the disabled prop should be applied (the inner, outer, nested, all of them?)
in the menubar case, there's only one instance of the menubar on the page so its clear where the settings props go
atomiks
left a comment
There was a problem hiding this comment.
Agree that settings don't need to be added here. Thanks for the fix!
Bundle size report
Check out the code infra dashboard for more information about this PR. |
disabled prop not working
Summary
The
disabledprop onContextMenu.Rootwas not preventing the context menu from opening.When opened with
disabledprop the context menu would completely block the page and could not be closed with clicks outside or ESC key.Here's a recording of the issue:
Screen.Recording.2026-01-21.at.11.04.57.mov
This PR fixes the issue by checking the
disabledstate inContextMenuTriggerbefore opening the menu:Screen.Recording.2026-01-21.at.16.02.21.mov
Changes
disabledstate inContextMenuTriggerbefore opening on right-click (handleContextMenu) and long press (handleTouchStart)disabledprop covering both right-click and long press (touch) interactionsTest plan
disabled={true}disabled={true}onOpenChangeis not called when the menu is disabledpnpm test:jsdom ContextMenu)