Overlays
Context menu
Right-click actions next to the object.
Usage
Wrap an area in ContextMenuTrigger and describe the actions in ContextMenuContent. The menu opens at the pointer on right-click, on a long press (500ms) on touch, and from the keyboard with Shift + F10 or the ContextMenu key. Items, labels, separators, checkbox and radio items and submenus are the dropdown menu's own parts under a ContextMenu name.
Right-click a file (long-press on touch)
When to use
- Shortcuts to actions on an object that already has a visible way to reach them (rows, cards, canvas items).
- Never the only way to do something: touch and keyboard users must be able to reach the same actions from a visible control.
Not for: the primary actions of a screen (use buttons), or a menu opened from a button (use the dropdown menu).
API
ContextMenu
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | — | Controlled open state. |
| defaultOpen | boolean | false | Initial state when uncontrolled. |
| onOpenChange | (open: boolean) => void | — | Called when the menu asks to open or close. |
ContextMenuTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
| asChild | boolean | — | Use your own element as the area. |
| disabled | boolean | — | Let the browser show its own context menu. |
| longPressDelay | number | 500 | Touch long-press time, ms. |
| tabIndex | number | 0 | The area must be focusable for the keyboard shortcut. |
ContextMenuContent
| Prop | Type | Default | Description |
|---|---|---|---|
| placement | 'bottom-start' | … | 'bottom-start' | Side and alignment against the pointer; flips and shifts to stay on screen. |
| offset | number | 2 | Gap to the pointer, px. |
Also: ContextMenuItem (icon, shortcut, variant, disabled, onSelect), ContextMenuCheckboxItem, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuLabel, ContextMenuSeparator, ContextMenuGroup, ContextMenuSub, ContextMenuSubTrigger and ContextMenuSubContent. They take the same props as their DropdownMenu counterparts.
Keyboard
| Key | Action |
|---|---|
| Shift + F10 / ContextMenu | On the area: opens the menu with the first item focused. |
| ↓ / ↑ | Next / previous item (wraps around). |
| Home / End | First / last item. |
| A–Z | Typeahead: jumps to the item that starts with what you type. |
| Enter / Space | Chooses the item. |
| → / ← | Opens / closes a submenu. |
| Esc | Closes the menu and returns focus to the area. |
| Tab | Closes the menu. |
Accessibility
- role="menu" with menuitem, menuitemcheckbox and menuitemradio items, the same as the dropdown menu.
- The trigger area is focusable so the keyboard can reach the menu; a menu opened with the keyboard lands on its first item.
- Focus returns to the area on close, except after a click outside.
- Touch: long press opens it; the page text selection and the iOS callout are switched off on the area.
Motion
- Open: pops from the pointer, scale .96 (150ms, ease-out). Close: 160ms fade.
- Reduced motion: it appears and disappears without movement.