ContextMenu
A context-triggered command menu supporting right-click, touch long-press, and keyboard shortcuts.
Base ContextMenu opens a floating command menu on right-click, touch/pen long-press, or keyboard shortcuts (ContextMenu / Shift+F10), with built-in keyboard navigation, typeahead, and focus restoration.
Preview
Section titled “Preview” Web Components React Vue Vue 2
Loading interactive preview… The article and source are ready to read. Interactive controls will appear here when ready.
Installation
Section titled “Installation”Available starting in 0.3.0-rc.1 and later releases.
Anatomy
Section titled “Anatomy”Compose Root, Trigger, Content, Item, and optional Group, Label, Separator, CheckboxItem, RadioGroup, RadioItem, Sub, SubTrigger, and SubContent:
Rootmanages open state (open/defaultOpen),disabled, andcloseOnItemCommit.Triggeropens on right-click,ContextMenu/Shift+F10, or a 600 ms touch/pen hold within movement tolerance, suppressing the native context menu while leaving ordinary clicks and scrolling untouched.Contenthandles overlay positioning, focus navigation, typeahead, and transitions (default placementbottom/start). Right-click and long-press anchor to the pointer location, while keyboard activation and programmaticopenContextMenu()fall back to the trigger region.Group,Label, andSeparatorprovide group naming and dividers;CheckboxItemandRadioGroup/RadioItemexposemenuitemcheckboxandmenuitemradiosemantics and keep the menu open by default;Sub,SubTrigger, andSubContentadd nested submenus with parent-close cascade.
Controlled state and focus return
Section titled “Controlled state and focus return”- Pass
openfor controlled mode: accepted trigger gestures still suppress the native context menu while letting your application decide whether to open. - Dismissing with
Escapeor selecting an item restores focus to the trigger.
Root Props
Section titled “Root Props”Passing open selects controlled mode.
| Prop | Type | Default |
|---|---|---|
open | boolean | — |
defaultOpen | boolean | false |
disabled | boolean | false |
closeOnItemCommit | boolean | true |
openEntry | string | active-or-first |
openEntryValue | string | '' |
Other parts
Section titled “Other parts”- Trigger: no props.
- Content: accepts Transition props; defaults
sideto'bottom',alignto'start',sideOffsetandalignOffsetto0,avoidCollisionstotrue,collisionPaddingto0, andexcludeAnchorTranslationtofalse. - Item:
disableddefaults tofalse,valueandtextValuedefault to''; optionalcloseOnCommitoverrides theRootpolicy. - Group / Label / Separator:
Groupacceptsa11yLabel('') and links to a scopedLabel;Separatorexposes horizontalrole="separator". - CheckboxItem / RadioGroup / RadioItem:
CheckboxItemsupportschecked,defaultChecked,indeterminate, andcloseOnCommit/closeOnSelect;RadioGroupsupportsvalue,defaultValue,disabled, anda11yLabel;RadioItemrequiresvalueand keeps the menu open by default. - Sub / SubTrigger / SubContent:
Subacceptsopen,defaultOpen,disabled;SubTriggeracceptsvalue,textValue,disabled;SubContentdefaults to'right'/'start'placement with positioning and Transition props.