Skip to content

ContextMenu

A right-click (or long-press) menu that surfaces contextual actions for a target element.

  • stable
  • since v0.1.0
  • 3.5 kB
  • overlay
  • menu
  • accessible

Opens on the contextmenu event or platform menu key; uses role="menu" / role="menuitem"; arrow keys navigate; Esc closes and restores focus.

Preview
Open
tsx

Nest ContextMenuSub + ContextMenuSubTrigger + ContextMenuSubContent to render hierarchical actions.

Preview
Open
tsx

Use ContextMenuCheckboxItem for toggles and ContextMenuRadioItem inside a ContextMenuRadioGroup for mutually-exclusive selection.

Preview
Open
tsx

ContextMenuShortcut renders kbd-style chips after the item label. They are decorative and not announced.

Preview
Open
tsx
PropTypeDefaultDescription
container
HTMLElement|(() => HTMLElement)
className
string
  • Opens via the native contextmenu event (right-click, two-finger tap, long-press) or the platform menu key while the trigger has focus.
  • ContextMenuContent carries role="menu"; items expose role="menuitem".
  • Arrow keys move between items; Home / End jump to the first / last; type-ahead also selects the first matching item.
  • Pressing Esc closes the menu and returns focus to the previously focused element.
  • ContextMenuCheckboxItem reports role="menuitemcheckbox"; ContextMenuRadioItem reports role="menuitemradio".
  • Wrap your trigger in asChild so the right-click handler attaches to your own element rather than an extra wrapper div.
  • Mirror the same item set in a toolbar or DropdownMenu so users can rely on either surface.
  • Use ContextMenuLabel to group nameable sections inside long menus.
  • Put destructive actions last under a ContextMenuSeparator so they are never the default landing item.