4.2.0
Core

ContextMenu

A menu of actions summoned by right-clicking the thing it acts on — the fastest path to a command, and the only one with no visible affordance.

Context menu

Right-click the region. `ContextMenuLabel` names what the menu is acting on, which a menu with no visible trigger has to say out loud, and `ContextMenuGroup` keeps the commands that belong together from drifting apart as the list grows.

Right-click here

Usage

import {
  ContextMenu,
  ContextMenuCheckboxItem,
  ContextMenuContent,
  ContextMenuGroup,
  ContextMenuItem,
  ContextMenuLabel,
  ContextMenuPortal,
  ContextMenuRadioGroup,
  ContextMenuRadioItem,
  ContextMenuSeparator,
  ContextMenuShortcut,
  ContextMenuSub,
  ContextMenuSubContent,
  ContextMenuSubTrigger,
  ContextMenuTrigger,
} from '@oceanic-hub/brand-system'
<ContextMenu>
  <ContextMenuTrigger>…</ContextMenuTrigger>
  <ContextMenuContent>
    <ContextMenuLabel>…</ContextMenuLabel>
    <ContextMenuSeparator>…</ContextMenuSeparator>
    <ContextMenuGroup>
      <ContextMenuItem>
        <ContextMenuShortcut>…</ContextMenuShortcut>
      </ContextMenuItem>
    </ContextMenuGroup>
  </ContextMenuContent>
</ContextMenu>

Composition

Use the following composition to build a ContextMenu:

ContextMenu
├── ContextMenuTrigger
└── ContextMenuContent
    ├── ContextMenuLabel
    ├── ContextMenuSeparator ×2
    ├── ContextMenuGroup ×2
    │   └── ContextMenuItem ×2
    │       └── ContextMenuShortcut
    ├── ContextMenuItem ×6
    │   └── ContextMenuShortcut
    ├── ContextMenuSub ×2
    │   ├── ContextMenuSubTrigger
    │   └── ContextMenuSubContent
    │       └── ContextMenuItem ×3
    ├── ContextMenuCheckboxItem ×2
    └── ContextMenuRadioGroup
        └── ContextMenuRadioItem ×4

That last clause is the whole rule: a context menu is never the only way to do something. Nothing on screen says it is there, so anything reachable only by right-click is reachable only by readers who already knew. Every command in one must also exist somewhere visible — a row menu, a toolbar, a details panel — and the right-click is the shortcut for the people who use the screen daily.

Reach for it when a list has many rows and each needs the same handful of commands. One ContextMenu per row costs no pixels; a DropdownMenu per row adds a button to every line, and a table with 200 kebab buttons is a table that has given a third of its width to chrome. That is the trade the three menus differ on: DropdownMenu belongs to a control you can see, Menubar is always on screen and acts on the whole screen, and this one belongs to whatever the pointer is over and shows nothing until asked. All three draw as one object, and since @OCE-1870 that is true of the rendered pixels and not only of the intent — including the motion. A right-click is still a click, so this panel pops rather than fading: core-layer.md § Motion keys the choice on how a surface was summoned, not on which button did it.

The trigger is a region, not a button — a row, a card, a canvas — so it is usually asChild around an element you already have. A row that cannot be acted on should disable the trigger rather than open a menu of disabled items: an empty menu still costs the reader the round-trip.

Because it is anchored to the pointer rather than to an element, it points at nothing meaningful, which is why there is no ContextMenuArrow — and elevation here is a hairline border, so an arrow would be a second signal for a job already done.

Upstream's Sides example does not port, and the reason is a generation difference rather than a refusal. shadcn's page is Base UI now and places a submenu with side="inline-end"; Radix, which this is built on, takes physical sides only — top, right, bottom, left — and inline-end is not one of them, so the example is a type error here, not a styling choice. Set placement with a physical side; Radix already flips it on collision, which is what the logical value existed to do.

Upstream's Shortcuts example is folded rather than duplicated, the way DropdownMenu's is: ContextMenuShortcut is in the lead demo, so nothing here is silently missing.

variant="destructive" is refused. Upstream marks a dangerous item by painting its label red. core-layer.md: "Never write a status tone as a text colour" — the status tones are bright mid-tones chosen to work as fills, and text-stuck measured 4.03:1, below AA, on Button before @OCE-1747 moved that label back to ink. What survives is the half that was always right: copy carries the severity. "Delete 12 contacts permanently" is unambiguous; a red item that says "Delete" is not. The Destructive actions section below shows what we do instead.

RTL is not supported. Upstream ships an RTL demo; we do not, because nothing in this package has ever been laid out or measured right-to-left. The refusal is written down in pairings.json under direction.

Nest a branch under ContextMenuSub when a command needs a target — "Move to", "Assign to" — so the top level stays short enough to read in the second a right-click buys you. Placement is a physical side and Radix flips it on collision, which matters more here than anywhere else: a pointer-anchored menu can open within a few pixels of any edge.

Right-click here

Checkbox items

On a right-click menu a toggle is worth less than on the other two — nothing on screen shows its state until the menu is summoned — so keep these to settings whose effect is visible on the row itself. Selecting an item closes the menu by default; preventDefault() on select holds it open, and inset puts the plain items on the same left edge as the ticks, which is the only thing stopping a mixed menu looking broken.

Right-click here

Radio items

A property of the thing under the pointer, changed in place. Reach for radio items over checkboxes when the values are mutually exclusive — a status, an owner, a priority — and over a submenu of plain items when the reader needs to see which one is live before choosing.

Right-click here

With icons

A right-click menu is read in a hurry, which is exactly where a leading glyph pays: the reader aims at the shape they used yesterday. All items take one or none do, otherwise the labels sit on two left edges. ContextMenuItem carries the gap already, so the icon needs no spacing class — but a checkbox or radio item does not, because its left inset is an indicator column rather than a flex gap.

Right-click here

Destructive actions

Upstream paints the item red; this package does not, because a status tone is a fill and never text. What carries the danger instead is the label — "Delete 12 contacts permanently" states the count and the finality — plus a separator that puts the action outside the group above it, so nobody arrives on it by momentum. A menu item is the wrong place to confirm, so anything unrecoverable opens AlertDialog rather than firing on select.

Right-click the selection

API Reference

See the ContextMenu API page for every prop of every part, with types, defaults and the contract that pins them.

On this page