Installation
Theme
Mode

Overlays & feedback

Context menu

A right-click menu that opens exactly where the cursor is and offers the actions relevant to whatever was clicked. Icons, shortcuts, danger actions, toggles and nested submenus — keyboard-navigable, edge-aware, and dismissed by Escape or an outside click.

$npx shadcn@latest add @orbit/context-menu

Overview

Live components — right-click any panel below. Each surface offers a different set of actions; hover “Move to” or “Sort by” for a submenu.

taskrow actions
Right-click this taskOpen · Rename · Move to ▸ · Delete
boardcanvas
Right-click the boardNew · Sort by ▸ · Show completed
fileattachment
Right-click the fileOpen · Download · Share · Delete

Inside the menu

Every row type the component can render: a quiet mono group label naming what the menu acts on, action rows with an icon and optional shortcut, a chevron row that opens a second panel on hover or →, checkable rows that stay open and show a ✓ while enabled, hairline separators, and a red destructive row set apart below a divider.

Right-click to inspect each row type
Right-click this taskOpen · Rename · Move to ▸ · Delete

Predictable by default

Opens at the cursor, not at a fixed corner. Near a viewport edge the panel shifts inward and submenus flip to the other side so nothing is clipped. Arrow keys move the highlight, → and ← enter and leave submenus, Enter activates, and Escape, an outside click, or picking an action closes it cleanly.

Try right-clicking near the viewport edge
Right-click the boardNew · Sort by ▸ · Show completed

Props

ContextMenu wraps Base UI ContextMenu; rows share the dropdown menu's styling. Every part forwards ...rest (and ref) to its underlying element, and raw parts are re-exported as ContextMenuPrimitive.

<ContextMenuTrigger> · <ContextMenuContent>

PropTypeDefaultDescription
ContextMenuTriggercomponentThe right-clickable surface. Renders a div around your content; long-press opens it on touch.
widthstring"220px"On ContextMenuContent: fixed panel width.

<ContextMenuItem>

PropTypeDefaultDescription
iconReactNode16px leading icon, rendered ink-soft (danger items render it in danger).
shortcutstringTrailing mono hint like "⌘D" or "F2" (quiet text, no keycap chip in this spec).
dangerbooleanfalseDestructive styling: danger text and a danger-soft highlight.
disabledbooleanfalseFades the row and blocks activation.
onClick(event) => voidFired when the item is activated; the menu closes afterwards.

<ContextMenuCheckboxItem> · <ContextMenuRadioGroup> · <ContextMenuRadioItem>

PropTypeDefaultDescription
checked / onCheckedChangeboolean / (checked) => voidCheckbox row state — shows a trailing ✓ and keeps the menu open on toggle.
value / onValueChangeany / (value) => voidOn ContextMenuRadioGroup: the selected row's value (used for submenu pickers like Move to).
iconReactNodeLead element in the 16px slot — an icon or a color/status dot.

<ContextMenuSub> · <ContextMenuSubTrigger> · <ContextMenuSubContent>

PropTypeDefaultDescription
ContextMenuSubTrigger iconReactNode16px leading icon; a trailing chevron is added automatically.
ContextMenuSubContent sideOffsetnumber2Gap between the parent panel edge and the flyout.
ContextMenuSubContent alignOffsetnumber-5Vertical shift so the first sub-row lines up with its trigger.
ContextMenuLabel / ContextMenuSeparatorcomponentQuiet mono group caption · hairline divider bleeding to the panel edges.

Usage

A context menu is a shortcut, never the only path. Every action it offers should also be reachable from a visible control or the command palette.

Do

Mirror the visible actions

Offer the same operations available from toolbars and the “⋯” menu, just faster to reach.

Don’t

Hide critical actions here

Right-click is a discovery dead-end on touch. Never make it the only way to do something important.

Do

Group and separate

Cluster related actions, divide with separators, and isolate destructive items at the bottom.

Don’t

Overfill the menu

Keep it to the dozen-or-so actions that fit the object. Push the long tail into submenus or settings.

Keyboard & accessibility

Built on Base UI ContextMenu: role=menu/menuitem, roving focus, typeahead, edge-aware positioning, and long-press support on touch devices.

Right-clickOpens the menu at the pointer position
↑ ↓Moves the highlight, skipping separators
→ ←Opens and closes a submenu
Activates the highlighted action
EscCloses the submenu, then the menu
Outside clickAny outside click dismisses it