Context Menu
A cursor-anchored right-click menu with type-ahead, submenus, checkable states, and viewport-aware flipping. Opens on right-click, Ctrl+click, long-press, or Shift+F10.
Installation#
pnpm dlx shadcn@latest add @davinciui/context-menuUsage#
Composition
A trigger area opens a floating panel at the cursor. Items, labels, separators, checkbox and radio states, and nested submenus compose declaratively — the menu owns focus, type-ahead, keyboard flow, flipping, and dismissal. Right-click, Ctrl+click, long-press, or Shift+F10 all open it; arrows move, Enter selects, Esc closes.
Basic#
Rich items#
Shortcuts#
Groups#
Icons#
Checkboxes#
Radio#
Destructive#
Sides#
Long lists + type-ahead#
Disabled#
Multiple contexts#
RTL#
Composition#
Use the following composition to build a Context Menu:
ContextMenu
└── ContextMenuTrigger
└── ContextMenuContent
├── ContextMenuGroup
│ ├── ContextMenuLabel
│ ├── ContextMenuItem
│ ├── ContextMenuCheckboxItem
│ └── ContextMenuRadioGroup
│ └── ContextMenuRadioItem
├── ContextMenuSeparator
└── ContextMenuSub
├── ContextMenuSubTrigger
└── ContextMenuSubContentAPI Reference#
| Prop | Type | Default |
|---|---|---|
openControlled open state. | boolean | — |
defaultOpenUncontrolled initial open state. | boolean | false |
onOpenChangeFires when the menu opens or closes. | (open: boolean, details: { reason?: string }) => void | — |
dirMirrors submenu sides and chevrons. | "ltr" | "rtl" | "ltr" |
ContextMenuContent · sideOffsetOffset from the cursor along the opening axis. | number | 4 |
ContextMenuContent · collisionPaddingSafe-area padding for viewport flipping. | number | 8 |
ContextMenuItem · iconLeading icon. | React.ReactNode | — |
ContextMenuItem · descriptionSecond line of muted detail text. | React.ReactNode | — |
ContextMenuItem · shortcutRight-aligned shortcut hint. | string | — |
ContextMenuItem · kbdKeycap-style shortcut, e.g. [⌘, C]. | string[] | — |
ContextMenuItem · badgeTrailing badge / count pill. | React.ReactNode | — |
ContextMenuItem · destructiveDestructive styling. | boolean | false |
ContextMenuItem · insetIndent to align with checkable items. | boolean | false |
ContextMenuItem · closeOnClickClose the menu after selection. | boolean | true |
ContextMenuCheckboxItem · checkedControlled checked state. | boolean | — |
ContextMenuCheckboxItem · onCheckedChangeFires on toggle. | (checked: boolean) => void | — |
ContextMenuRadioGroup · valueControlled selected value. | string | — |
ContextMenuRadioGroup · onValueChangeFires on select. | (value: string) => void | — |
ContextMenuSub · labelSubmenu trigger label. | React.ReactNode | — |
ContextMenuSub · iconLeading icon on the trigger. | React.ReactNode | — |
ContextMenuSub · disabledDisables the submenu trigger. | boolean | false |
Accessibility#
Base UI supplies role='menu', roving focus, type-ahead, Escape dismissal, and focus return. Right-click, Ctrl+click, long-press, and Shift+F10 open it while focus is inside. The trigger wrapper is a plain non-tabbable div, so add tabIndex for keyboard-only access; section labels and shortcuts are aria-hidden.
Motion#
The popup enters and exits over 150ms with opacity, 4px translate, and 0.96 scale using cubic-bezier(0.23,1,0.32,1). Items press to 0.99 scale in 75ms. motion-reduce:transition-none removes the popup transition and starting transform; no easing props are exposed.
View source
Keep in mind
Need a custom component?
I build bespoke UI components & websites tailored to your brand.

