Navigation
Context Menu
Right-click menu with the same parts and look as Menu, opened at the pointer.
Installation
Install the package (React 19):
Import the styles once, in your app entry or root layout:
Use it anywhere inside your app's <Theme> (see Installation):
Examples
Right-click area
Composition
- Same item parts and props as Menu (
Item,CheckboxItem,RadioGroup,RadioItem,ToggleItem,Label,Separator,Group,Sub,SubTrigger,SubContent).
API Reference
ContextMenu.Root
Holds the open state (opened by the pointer, so only onOpenChange).
| Prop | Type | Default |
|---|---|---|
onOpenChange | (open: boolean) => void | |
modal | boolean | true |
ContextMenu.Trigger
The area that opens the menu.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | false |
disabled | boolean | false |
ContextMenu.Content
The floating menu, positioned at the pointer.
| Prop | Type | Default |
|---|---|---|
width | number | |
header | ReactNode | |
footer | ReactNode | |
side | "top""right""bottom""left" | |
align | "start""center""end" | |
collisionPadding | number | 8 |
alignOffset | number | 0 |
loop | boolean | false |
ContextMenu.Item
An action row.
| Prop | Type | Default |
|---|---|---|
icon | IconName | ReactNode | |
children | ReactNode | |
description | ReactNode | |
caption | ReactNode | |
shortcut | ReactNode | |
submenu | boolean | false |
checked | boolean | false |
toggle | boolean | |
trailing | ReactNode | |
tone | "default""danger""accent""muted" | "default" |
destructive | boolean | false |
disabled | boolean | false |
onSelect | (event: Event) => void | |
textValue | string |
ContextMenu.CheckboxItem
An on/off option (menuitemcheckbox) with a trailing checkmark when checked.
| Prop | Type | Default |
|---|---|---|
icon | IconName | ReactNode | |
children | ReactNode | |
description | ReactNode | |
caption | ReactNode | |
shortcut | ReactNode | |
checked | boolean | "indeterminate" | |
onCheckedChange | (checked: boolean) => void | |
disabled | boolean | false |
onSelect | (event: Event) => void | |
textValue | string |
ContextMenu.RadioGroup
Groups RadioItems; exactly one is selected.
| Prop | Type | Default |
|---|---|---|
value | string | |
onValueChange | (value: string) => void |
ContextMenu.RadioItem
One option of a RadioGroup (menuitemradio), checkmark when selected.
| Prop | Type | Default |
|---|---|---|
icon | IconName | ReactNode | |
children | ReactNode | |
description | ReactNode | |
caption | ReactNode | |
shortcut | ReactNode | |
value | string | |
disabled | boolean | false |
onSelect | (event: Event) => void | |
textValue | string |
ContextMenu.ToggleItem
Motion extra: an on/off row drawn with a switch. Keeps the menu open when toggled.
| Prop | Type | Default |
|---|---|---|
icon | IconName | ReactNode | |
children | ReactNode | |
description | ReactNode | |
caption | ReactNode | |
checked | boolean | |
onCheckedChange | (checked: boolean) => void | |
disabled | boolean | false |
onSelect | (event: Event) => void | |
textValue | string |
ContextMenu.Sub
Wraps a submenu (SubTrigger + SubContent).
| Prop | Type | Default |
|---|---|---|
open | boolean | |
defaultOpen | boolean | false |
onOpenChange | (open: boolean) => void |
ContextMenu.SubTrigger
Row that opens a submenu (→ or Enter opens, ← closes). Draws the chevron itself.
| Prop | Type | Default |
|---|---|---|
icon | IconName | ReactNode | |
children | ReactNode | |
description | ReactNode | |
caption | ReactNode | |
disabled | boolean | false |
textValue | string |
ContextMenu.SubContent
The submenu surface (portalled).
| Prop | Type | Default |
|---|---|---|
width | number | |
sideOffset | number | 2 |
collisionPadding | number | 8 |
ContextMenu.Label / Separator / Group
Section label, hairline separator and a grouping wrapper.
| Prop | Type | Default |
|---|---|---|
className | string |
ContextMenu.Search / ContextMenu.Footer
Search: filter field for the header slot (its accessible name defaults to the placeholder). Footer: grey metadata lines for the footer slot.
| Prop | Type | Default |
|---|---|---|
noIcon | boolean | false |
wrapperClassName | string | |
lines | ReactNode[] | |
separator | boolean | true |
Accessibility
- Follows the WAI-ARIA menu pattern. Opens on right-click, long-press on touch, or the context menu key / Shift+F10 while the trigger area has focus.
- Focus moves into the menu; ↑/↓, Home/End, typeahead, Enter/Space, → / ← for submenus, Escape to close.
- Stays inside the viewport (8px collision padding) and scrolls when it is taller than the space left.
- Opens and closes with the shared motion layer (
styles/motion.css); withprefers-reduced-motion: reduceit only fades.
Usage
- Use as a shortcut to actions that are also available elsewhere (a Menu button, a toolbar).
- Don't hide the only way to do something in a context menu: it is invisible until discovered, and harder on touch.
- Keep it short and in the same order as the matching Menu.