Context Menu
A menu of actions for the thing under the pointer. It springs open from where you clicked, shares its rows with the Dropdown Menu, and a raised pill slides between them as you move.
Install
npx shadcn@latest add @nelumbo/context-menuActions
Right-click the area. On touch, press and hold; on a keyboard, focus it and press Shift+F10 or the Menu key. Icons on the left, keycap shortcuts on the right, a submenu, and a destructive action set apart at the end.
Options
Checkbox items toggle without closing the menu; a radio group picks one, and the chosen row fills in with the tonal container.
Usage
import { ContextMenu, ContextMenuTrigger, ContextMenuContent, ContextMenuItem, ContextMenuShortcut, ContextMenuSeparator } from "@/components/ui/context-menu"<ContextMenu> <ContextMenuTrigger className="grid h-40 place-items-center rounded-2xl bg-surface-container-high"> Right-click here </ContextMenuTrigger> <ContextMenuContent className="w-60"> <ContextMenuItem> <Icon name="content_copy" /> Copy <ContextMenuShortcut>⌘C</ContextMenuShortcut> </ContextMenuItem> <ContextMenuSeparator /> <ContextMenuItem variant="destructive"> <Icon name="delete" /> Delete </ContextMenuItem> </ContextMenuContent></ContextMenu>Props
Everything else is Radix Context Menu (onOpenChange, modal, onSelect, checked, value…). The trigger is not a button: give it tabIndex={0} if keyboard users should reach it, since Shift+F10 and the Menu key open the menu from whatever has focus.
| Prop | Type | Default | Notes |
|---|---|---|---|
ContextMenuItem variant | "default" | "destructive" | "default" | |
inset | boolean | false | Item, Label, SubTrigger: align with items that have an icon |
ContextMenuShortcut | string | Drawn as keycaps: "⌘C" and "⌘ C" become two caps |