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 | undefined, reason: OpenChangeReason | undefined) => void)

undefined

actionsRef

RefObject<{ unmount: () => void; }>

undefined

closeParentOnEsc

boolean

true

modal

boolean

true

onOpenChangeComplete

((open: boolean) => void)

undefined

disabled

boolean

false

openOnHover

boolean

undefined

delay

number

100

loop

boolean

true

orientation

MenuOrientation

'vertical'

children*

ReactNode

Trigger

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

PropTypeDefault
className

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

undefined

render

| ReactElement
| ((props: GenericHTMLProps, state: 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
align

'center' | 'end' | 'start'

'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: State) => string)

undefined

render

| ReactElement
| ((props: GenericHTMLProps, state: 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
id

string

undefined

children

ReactNode

undefined

className

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

undefined

render

| ReactElement
| ((props: GenericHTMLProps, state: 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: State) => string)

undefined

render

| ReactElement
| ((props: GenericHTMLProps, state: 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: State) => string)

undefined

render

| ReactElement
| ((props: GenericHTMLProps, state: 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: State) => string)

undefined

render

| ReactElement
| ((props: GenericHTMLProps, state: State) => ReactElement)

undefined

GroupLabel

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

PropTypeDefault
className

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

undefined

render

| ReactElement
| ((props: GenericHTMLProps, state: 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: State) => string)

undefined

render

| ReactElement
| ((props: GenericHTMLProps, state: 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: State) => string)

undefined

render

| ReactElement
| ((props: GenericHTMLProps, state: 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: State) => string)

undefined

keepMounted

boolean

false

render

| ReactElement
| ((props: GenericHTMLProps, state: 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: State) => string)

undefined

render

| ReactElement
| ((props: GenericHTMLProps, state: 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: State) => string)

undefined

keepMounted

boolean

false

render

| ReactElement
| ((props: GenericHTMLProps, state: State) => ReactElement)

undefined

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

A menu item that opens a submenu. Renders a <div> element.

PropTypeDefault
label

string

undefined

onClick

MouseEventHandler<HTMLElement>

undefined

id

string

undefined

children

ReactNode

undefined

className

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

undefined

render

| ReactElement
| ((props: GenericHTMLProps, state: State) => ReactElement)

undefined

Attribute
Description
data-popup-open

Separator

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

PropTypeDefault
orientation

Orientation

'horizontal'

className

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

undefined

render

| ReactElement
| ((props: GenericHTMLProps, state: State) => ReactElement)

undefined

Examples

Advanced demos are available at the main Menu page, most of which apply to the context menu as well.

Nested menu

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

Right click here