Context Menu opens a list of actions where the user right-clicks, long-presses on a touch screen, or presses Shift+F10 or the Menu key. It lives in the browser top layer as a popover, sits at the pointer and flips away from the viewport edges. Items look and behave like the ones in Dropdown Menu, plus checkbox and radio items, labels, shortcuts and nested submenus.
Browser Support
Limited availability4 featuresDetails
Shows the menu in the top layer with light dismiss. Submenus are nested popovers, so the parent stays open.
Places the menu at the pointer and flips it near the edges. Without it, JavaScript measures the menu and clamps it into the viewport.
Fades and scales the menu in. Without it the menu appears instantly.
Keeps the closing animation running while the popover leaves the top layer.
Preview
Right-click a file, long-press it on a touch screen, or focus it with Tab and press Shift+F10.
Q3 revenue forecast.xlsx
248 KB · edited 2 h ago
Onboarding checklist.docx
36 KB · edited yesterday
Offsite Lisbon 2026
142 photos
Homepage hero v4.png
1.8 MB · edited Nov 12
Installation
Usage
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuSeparator,
ContextMenuTrigger,
} from "@/components/ui/context-menu"
export function FileCard() {
return (
<ContextMenu>
<ContextMenuTrigger aria-label="report.pdf. Shift+F10 for actions" className="rounded-lg border p-4">
report.pdf
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem shortcut="⌘O" onSelect={() => open()}>Open</ContextMenuItem>
<ContextMenuItem shortcut="⌘D" onSelect={() => duplicate()}>Duplicate</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem variant="destructive" onSelect={() => remove()}>Delete</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
)
}Examples
Checkbox and radio items
View options of a canvas: checkbox items toggle the grid and rulers, a radio group picks the zoom. Labels and inset keep the text aligned.
100% · show grid on
Type a letter to jump to an item: s cycles through Show grid and Snap to grid.
const [grid, setGrid] = useState(true)
const [zoom, setZoom] = useState("100")
<ContextMenu>
<ContextMenuTrigger aria-label="Canvas. Shift+F10 for view options">…</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuLabel inset>View</ContextMenuLabel>
<ContextMenuCheckboxItem checked={grid} onCheckedChange={setGrid} shortcut="⌘'">
Show grid
</ContextMenuCheckboxItem>
<ContextMenuSeparator />
<ContextMenuLabel inset id="zoom-label">Zoom</ContextMenuLabel>
<ContextMenuRadioGroup value={zoom} onValueChange={setZoom} aria-labelledby="zoom-label">
<ContextMenuRadioItem value="50">50%</ContextMenuRadioItem>
<ContextMenuRadioItem value="100">100%</ContextMenuRadioItem>
<ContextMenuRadioItem value="200">200%</ContextMenuRadioItem>
</ContextMenuRadioGroup>
</ContextMenuContent>
</ContextMenu>Submenu
ContextMenuSub nests another level. It opens on hover, click, Enter or Arrow Right and closes with Arrow Left or Escape.
<ContextMenuSub>
<ContextMenuSubTrigger>
<UsersIcon />
Share
</ContextMenuSubTrigger>
<ContextMenuSubContent>
<ContextMenuItem onSelect={copyLink}>Copy link</ContextMenuItem>
<ContextMenuItem onSelect={sendEmail}>Send by email</ContextMenuItem>
</ContextMenuSubContent>
</ContextMenuSub>Keep the menu open
Call event.preventDefault() in onSelect to keep the menu open, for example when several checkboxes are toggled in a row.
<ContextMenuCheckboxItem
checked={rulers}
onCheckedChange={setRulers}
onSelect={(event) => event.preventDefault()}
>
Rulers
</ContextMenuCheckboxItem>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| onOpenChange | (open: boolean) => void | - | ContextMenu: called when the menu opens or closes. |
| onSelect | (event) => void | - | Items: runs on click, Enter or Space. event.preventDefault() keeps the menu open. |
| variant | "default" | "destructive" | "default" | ContextMenuItem: red style for destructive actions. |
| shortcut | ReactNode | - | Items: hint such as ⌘D shown at the end of the item. |
| inset | boolean | false | Item, label, sub trigger: indent to line up with checkbox items. |
| textValue | string | - | Items: text for typeahead when the children are not plain text. |
| disabled | boolean | false | ContextMenuTrigger: let the browser show its own menu instead. Items: skip the item in keyboard navigation and clicks. |
| checked | boolean | - | ContextMenuCheckboxItem: controlled checked state. |
| defaultChecked | boolean | false | ContextMenuCheckboxItem: initial checked state. |
| onCheckedChange | (checked: boolean) => void | - | ContextMenuCheckboxItem: called with the new state. |
| value | string | - | ContextMenuRadioGroup: controlled selected value. |
| defaultValue | string | - | ContextMenuRadioGroup: initial selected value. |
| onValueChange | (value: string) => void | - | ContextMenuRadioGroup: called with the new value. |
| RadioItem value | string | - | ContextMenuRadioItem: value of this option. |
Components
| Component | Description |
|---|---|
| ContextMenu | Root. Holds the open state and the pointer position. |
| ContextMenuTrigger | Area that reacts to right-click, long-press, Shift+F10 and the Menu key. A focusable div. |
| ContextMenuContent | The menu itself, a popover with role=menu. |
| ContextMenuItem | Action. Supports icons, shortcut and variant. |
| ContextMenuCheckboxItem | Item with role=menuitemcheckbox. |
| ContextMenuRadioGroup | Group of radio items with one value. |
| ContextMenuRadioItem | Item with role=menuitemradio. |
| ContextMenuLabel | Small caption for a group of items. |
| ContextMenuSeparator | Thin line between groups. |
| ContextMenuShortcut | Keyboard hint at the end of an item. |
| ContextMenuSub | Wraps one nested level. |
| ContextMenuSubTrigger | Item that opens the submenu. |
| ContextMenuSubContent | The nested menu. |
Features
- Three ways to open — right-click, a 500 ms long-press on touch, Shift+F10 or the Menu key on a focused trigger
- Keyboard — arrows, Home and End move between items, a letter jumps to the matching item, Escape and Tab close the menu and return focus
- One highlight — the pointer moves focus, so the mouse and the keyboard never highlight two items at once
- Edges — the menu flips to the other side of the pointer when there is no room; submenus flip to the left
- Nested triggers — only the innermost trigger handles the gesture
- Reduced motion — the open animation is turned off