Context Menu

A menu that appears at the pointer on right click or long press.

Right click here

API reference

Import the components and place them together:

Anatomy

Root

A component that creates a context menu activated by right clicking or long pressing. Doesn’t render its own HTML element.

PropTypeDefault
defaultOpen

boolean

false

open

boolean

undefined

onOpenChange

(open: boolean, event?: Event, reason?: Menu.Root.OpenChangeReason) => void

undefined

actionsRef

RefObject<Actions>

undefined

closeParentOnEsc

boolean

true

onOpenChangeComplete

((open: boolean) => void)

undefined

disabled

boolean

false

loop

boolean

true

orientation

Menu.Root.Orientation

'vertical'

children*

ReactNode

Trigger

An area that opens the menu on right click or long press. Renders a <div> element.

PropTypeDefault
className

| string
| ((state: ContextMenu.Trigger.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: ContextMenu.Trigger.State) => ReactElement)

undefined

Portal

A portal element that moves the popup to a different part of the DOM. By default, the portal element is appended to <body>.

PropTypeDefault
container

| HTMLElement
| RefObject<HTMLElement
| null>
| null

undefined

children

ReactNode

undefined

keepMounted

boolean

false

Positioner

Positions the menu popup against the trigger. Renders a <div> element.

PropTypeDefault
collisionAvoidance

CollisionAvoidance

undefined

align

'center' | 'start' | 'end'

'center'

alignOffset

number | OffsetFunction

0

side

Side

'bottom'

sideOffset

number | OffsetFunction

0

arrowPadding

number

5

anchor

| Element
| RefObject<Element
| null>
| VirtualElement
| (() => Element | VirtualElement | null)
| null

undefined

collisionBoundary

Boundary

'clipping-ancestors'

collisionPadding

Padding

5

sticky

boolean

false

positionMethod

'fixed' | 'absolute'

'absolute'

trackAnchor

boolean

true

className

| string
| ((state: Menu.Positioner.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: Menu.Positioner.State) => ReactElement)

undefined

Attribute
Description
data-open
data-closed
data-anchor-hidden
data-align
data-side
CSS Variable
Description
--anchor-height
--anchor-width
--available-height
--available-width
--transform-origin

A container for the menu items. Renders a <div> element.

PropTypeDefault
finalFocus

RefObject<HTMLElement | null>

undefined

id

string

undefined

children

ReactNode

undefined

className

| string
| ((state: Menu.Popup.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: Menu.Popup.State) => ReactElement)

undefined

Attribute
Description
data-open
data-closed
data-align
data-instant
data-side
data-starting-style
data-ending-style

Arrow

Displays an element positioned against the menu anchor. Renders a <div> element.

PropTypeDefault
className

| string
| ((state: Menu.Arrow.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: Menu.Arrow.State) => ReactElement)

undefined

Attribute
Description
data-open
data-closed
data-uncentered
data-anchor-hidden
data-align
data-side

Item

An individual interactive item in the menu. Renders a <div> element.

PropTypeDefault
label

string

undefined

onClick

MouseEventHandler<HTMLElement>

undefined

closeOnClick

boolean

true

disabled

boolean

false

id

string

undefined

children

ReactNode

undefined

className

| string
| ((state: Menu.Item.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: Menu.Item.State) => ReactElement)

undefined

Attribute
Description
data-highlighted
data-disabled

Group

Groups related menu items with the corresponding label. Renders a <div> element.

PropTypeDefault
children

ReactNode

undefined

className

| string
| ((state: Menu.Group.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: Menu.Group.State) => ReactElement)

undefined

GroupLabel

An accessible label that is automatically associated with its parent group. Renders a <div> element.

PropTypeDefault
className

| string
| ((state: Menu.GroupLabel.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: Menu.GroupLabel.State) => ReactElement)

undefined

RadioGroup

Groups related radio items. Renders a <div> element.

PropTypeDefault
defaultValue

any

undefined

value

any

undefined

onValueChange

((value: any, event: Event) => void)

() => {}

disabled

boolean

false

children

ReactNode

undefined

className

| string
| ((state: Menu.RadioGroup.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: Menu.RadioGroup.State) => ReactElement)

undefined

RadioItem

A menu item that works like a radio button in a given group. Renders a <div> element.

PropTypeDefault
label

string

undefined

value*

any

onClick

MouseEventHandler<HTMLElement>

undefined

closeOnClick

boolean

false

disabled

boolean

false

id

string

undefined

children

ReactNode

undefined

className

| string
| ((state: Menu.RadioItem.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: Menu.RadioItem.State) => ReactElement)

undefined

Attribute
Description
data-checked
data-unchecked
data-highlighted
data-disabled

RadioItemIndicator

Indicates whether the radio item is selected. Renders a <div> element.

PropTypeDefault
className

| string
| ((state: Menu.RadioItemIndicator.State) => string)

undefined

keepMounted

boolean

false

render

| ReactElement
| ((props: HTMLProps, state: Menu.RadioItemIndicator.State) => ReactElement)

undefined

Attribute
Description
data-checked
data-unchecked
data-disabled
data-starting-style
data-ending-style

CheckboxItem

A menu item that toggles a setting on or off. Renders a <div> element.

PropTypeDefault
label

string

undefined

defaultChecked

boolean

false

checked

boolean

undefined

onCheckedChange

((checked: boolean, event: Event) => void)

undefined

onClick

MouseEventHandler<HTMLElement>

undefined

closeOnClick

boolean

false

disabled

boolean

false

id

string

undefined

children

ReactNode

undefined

className

| string
| ((state: Menu.CheckboxItem.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: Menu.CheckboxItem.State) => ReactElement)

undefined

Attribute
Description
data-checked
data-unchecked
data-highlighted
data-disabled

CheckboxItemIndicator

Indicates whether the checkbox item is ticked. Renders a <div> element.

PropTypeDefault
className

| string
| ((state: Menu.CheckboxItemIndicator.State) => string)

undefined

keepMounted

boolean

false

render

| ReactElement
| ((props: HTMLProps, state: Menu.CheckboxItemIndicator.State) => ReactElement)

undefined

Attribute
Description
data-checked
data-unchecked
data-disabled
data-starting-style
data-ending-style

Separator

A separator element accessible to screen readers. Renders a <div> element.

PropTypeDefault
orientation

Orientation

'horizontal'

className

| string
| ((state: Separator.State) => string)

undefined

render

| ReactElement
| ((props: HTMLProps, state: Separator.State) => ReactElement)

undefined

Examples

Menu displays additional demos, many of which apply to the context menu as well.

Nested menu

To create a submenu, nest Menu inside the parent context menu. Use the <Menu.SubmenuTrigger> part for the menu item that opens the nested menu.

Right click here