Context Menu

A menu of actions for an item that opens where the pointer right-clicks.

Basic usage

Wrap the target in ContextMenu.Trigger asChild; right-clicking it or long-pressing it on a touch screen opens the menu at the pointer. Items take the same start, end, destructive, and href props as Dropdown Menu items. An item with href renders as a link, so it supports opening in a new tab.

Right-clicking is hard to discover and unavailable to many keyboard users, so offer the same actions somewhere visible too, usually an ellipsis dropdown on the same card or row.

Weekly visibility reportRight-click to see actions

Labels, shortcuts, and submenus

Give each row its own ContextMenu.Root so the menu knows which item it acts on; the trigger gets data-state="open" while its menu is open, which you can use to highlight the row. ContextMenu.Label names a section, ContextMenu.Shortcut shows a key hint at the end of an item, and ContextMenu.Sub nests a submenu that opens on hover or with the right arrow key.

A disabled item with disabledReason stays hoverable and shows the reason in a tooltip, so people learn why the action isn't available.

Best espresso machines for home baristasCoffee gear
Which decaf coffee tastes the most like regular coffee?Coffee beans
Is a coffee subscription worth it?Subscriptions

Usage

ContextMenu.Trigger asChild needs a child that forwards its ref and props, such as a div. When the target is a link or a clickable row, stop the menu's click and key events from reaching it with onClick and onKeyDown on ContextMenu.Content.

ContextMenu.Root Properties

onOpenChange
(open: boolean) => void

Called when the menu opens or closes

modal
boolean

Blocks interaction outside the menu while it is open

Default: true

dir
'ltr''rtl'

Reading direction, which also sets which side submenus open on

ContextMenu.Trigger Properties

asChild
boolean

Uses the child element as the right-click target instead of a wrapping span

Default: false

disabled
boolean

Lets the browser's own context menu open instead

Default: false

ContextMenu.Content Properties

size
number

Minimum width in pixels

Default: 249

alignOffset
number

Offset from the pointer along the alignment axis

Default: 0

collisionPadding
numberPartial<Record<Side, number>>

Space to keep from the viewport edges

Default: 0

onCloseAutoFocus
(event: Event) => void

Called when focus returns to the trigger after closing. Call preventDefault to keep focus elsewhere

className
string

Classes for the menu surface

ContextMenu.Item Properties

start
IconNameIconPropsReactNode

Icon or element before the label

end
IconNameIconPropsReactNode

Icon or element after the label, aligned to the end

destructive
boolean

Shows the item in red for actions that remove data

Default: false

href
string

Renders the item as a link

target
string

Link target, such as _blank

rel
string

Link relationship. Use noopener noreferrer with target _blank

onSelect
(event: Event) => void

Called when the item is chosen. Call preventDefault to keep the menu open

disabled
boolean

Dims the item and prevents choosing it

Default: false

disabledReason
string

Tooltip explaining why a disabled item is unavailable. Keeps the item hoverable

ContextMenu.Label Properties

size
'small''medium'

Height and text size of the section label

Default: medium

ContextMenu.Sub Properties

open
boolean

Controlled open state of the submenu

onOpenChange
(open: boolean) => void

Called when the submenu opens or closes

ContextMenu.SubTrigger Properties

startIcon
IconNameIconPropsReactNode

Icon or element before the label. A chevron is always shown at the end

disabled
boolean

Dims the trigger and prevents opening the submenu

Default: false

ContextMenu.SubContent Properties

size
number

Minimum width in pixels

Default: 249

sideOffset
number

Distance from the parent menu in pixels

Default: 8

alignOffset
number

Vertical offset from the submenu trigger

Default: -4

pinnedBottom
ReactNode

Content fixed below the submenu's scrolling items, such as a create action

Other Parts

Separator
component

Divider line between groups of items

Shortcut
component

Key hint placed inside an item, after its label

Group
component

Groups related items without adding visible chrome

Portal
component

Radix portal. Content and SubContent already render in one