Base · Overlays
Context menu
A menu of actions that opens at the pointer when an area is right-clicked.
Props
import {
ContextMenu,
ContextMenuContent,
ContextMenuGroup,
ContextMenuItem,
ContextMenuLabel,
ContextMenuSeparator,
ContextMenuShortcut,
ContextMenuTrigger,
} from "@/components/ui/context-menu"
<ContextMenu>
<ContextMenuTrigger className="rounded-lg border border-dashed p-8 text-sm">
Right-click shipment SH-20418
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuGroup>
<ContextMenuLabel>Shipment</ContextMenuLabel>
<ContextMenuItem>
Open <ContextMenuShortcut>⌘O</ContextMenuShortcut>
</ContextMenuItem>
<ContextMenuItem>Copy tracking link</ContextMenuItem>
<ContextMenuItem>Assign driver</ContextMenuItem>
</ContextMenuGroup>
<ContextMenuSeparator />
<ContextMenuItem variant="destructive">Cancel shipment</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>Overview
A context menu offers the actions for the thing under the pointer: a table row, a file, a map pin. It is a shortcut for people who look for it, so every action in it must also be reachable another way.
When to use
- On rows, cards and canvas objects in tools people use all day, to speed up frequent actions.
- When the same actions already exist in a visible Dropdown menu or toolbar.
When not to use
- As the only way to reach an action. Nothing on screen says a context menu exists; add a Dropdown menu.
- On text, links and form fields, where people expect the browser's own menu.
- For application-wide commands: use a Menubar or a Command palette.
Anatomy
Trigger
The area that responds to right-click. It wraps your content and adds no styling.
Content
The floating list, placed at the pointer.
Group and label
Related items with an optional heading. A label must sit inside a group.
Item
An action, with an optional icon and shortcut. Has a destructive variant.
Checkbox, radio and submenu items
Same as in a Dropdown menu.
Props
The contract every language implements. Names follow each language’s conventions (camelCase in React, snake_case in Rust).
| Prop | Type | Default | Description |
|---|---|---|---|
| side | "right" | "left" | "top" | "bottom" | right | The side of the pointer the menu opens on. Set on ContextMenuContent. |
| align | "start" | "center" | "end" | start | How the menu lines up with the pointer along that side. |
| label | string | Right-click shipment SH-20418 | Text shown in the trigger area in this example. |
| onOpenChange | function | – | Called when the menu opens or closes. Set on the root. |
States
- Closed
- The trigger area looks like normal content.
- Open
- The menu appears at the pointer position and takes focus.
- Item highlighted
- The item under the pointer or keyboard focus has a muted background.
Accessibility
Role: menu
| Keys | Action |
|---|---|
| Shift+F10/Menu key | With focus inside the trigger area, opens the menu. |
| Arrow Down/Arrow Up | Moves the highlight between items. |
| Home/End | Highlights the first or last item. |
| Enter/Space | Activates the highlighted item and closes the menu. |
| Arrow Right/Arrow Left | Opens a submenu, or closes it and returns to its parent. |
| A–Z | Highlights the next item that starts with the typed characters. |
| Escape | Closes the menu. |
- The keyboard shortcut only works if something inside the trigger area can receive focus.
- On touch screens the menu opens on long-press.
- Provide every action elsewhere in the interface as well.
Design tokens
Change any of these in Foundations and this component follows, in every language.
Platform notes
- HTML / JS
- Planned
- Not built in HTML / JS yet.
- React
- Stable
- Matches the contract with no platform differences.
- React Native
- Draft
- Prop-driven: pass `items`, with the trigger area as children. Opens on long-press (and right-click on web) at the touch point on wide windows, or as an action sheet on phones.
- Swift (SwiftUI)
- Planned
- Not built in Swift yet.
- Godot
- Planned
- Not built in Godot yet.
- Vue
- Draft
- Usage snippet only; same props and behavior as the React component.
- Svelte
- Draft
- Usage snippet only; same props and behavior as the React component.
- Solid
- Draft
- Usage snippet only; same props and behavior as the React component.