Skip to content

Context Menu

A menu of contextual actions that opens on right-click or long press.

Right-click a row or open its menu

  • Pricing FAQ.pdf

    Indexed24 chunks
  • Refund policy.md

    Indexed18 chunks
  • Onboarding guide.docx

    Paused32 chunks
hero.tsx

Usage guidelines

  • Use ContextMenu as a shortcut to actions that are also reachable from a visible control, such as a Menu behind a "More actions" button. Touch, keyboard and assistive-technology users may not find or open a context menu.
  • Wrap the area that owns the actions in ContextMenuTrigger, such as a card, a list row or a canvas. The trigger is a plain <div> and not a focus stop: let its content describe it, and do not give it an aria-label or a tabIndex.
  • Keep the Menu with the same actions outside ContextMenu, as a sibling. A Menu inside ContextMenu joins the context menu instead of opening on its own.
  • Use ContextMenuContent for the popup at the pointer. Compose ContextMenuPortal, ContextMenuPositioner and ContextMenuPopup when the popup anchors to an element instead of the pointer, or when it renders into a custom container, such as a canvas in fullscreen.
  • Items, groups, submenus and checkbox or radio items follow the same rules as in Menu. A dialog that an item opens stays a sibling of the ContextMenu and opens through its handle.

Anatomy

tsx
tsx

ContextMenuContent bundles the portal, positioner and styled popup. ContextMenuPopup is the bare popup for a surface that places and dresses itself; compose it with ContextMenuPortal and ContextMenuPositioner.

Examples

Right-click the canvas to add blocks from a submenu or toggle the minimap. The "Canvas actions" menu offers the same items, so both share the minimap state.

Support triage workflow
Right-click the canvas
canvas.tsx

Anchoring to an element

ContextMenuPositioner takes an anchor, so the popup lines up with the workflow block instead of the pointer. ContextMenuPortal takes a container in the same way. The block's "More actions" menu offers the same actions.

Knowledge retrieval

Product docsTop 4
anchored.tsx

Keyboard

The trigger area is not a focus stop, so keyboard users open the same actions from the visible Menu. These keys apply once the context menu is open.

KeyAction
Down arroworUp arrowFocuses the first or last item after the menu opens, then moves focus between items.
HomeorEndFocuses the first or last item.
Printable charactersFocuses the next item whose label starts with the typed text.
EnterorSpaceActivates the focused item and closes the menu. Checkbox and radio items toggle and keep the menu open.
EnterorRight arrowOpens the submenu of a focused submenu trigger and focuses its first item.
Left arrowCloses the submenu and returns focus to its trigger.
EscapeCloses the innermost open menu.

API reference

ContextMenu

Groups all parts of a context menu opened by right-clicking or long-pressing a trigger area. Doesn't render its own HTML element.

Base UI ContextMenu.Root docs

ContextMenuCheckboxItem

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

Base UI Menu.CheckboxItem docs

Data attributes
AttributeDescription
data-checked

Present when the menu checkbox item is checked.

data-unchecked

Present when the menu checkbox item is not checked.

data-disabled

Present when the menu checkbox item is disabled.

data-highlighted

Present when the menu checkbox item is highlighted.

ContextMenuCheckboxItemIndicator

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

Base UI Menu.CheckboxItemIndicator docs

Data attributes
AttributeDescription
data-checked

Present when the menu checkbox item is checked.

data-unchecked

Present when the menu checkbox item is not checked.

data-disabled

Present when the menu checkbox item is disabled.

data-starting-style

Present when the indicator begins animating in.

data-ending-style

Present when the indicator is animating out.

ContextMenuContent

A styled context menu popup bundled with a portal and positioner. Renders a <div> element.

Base UI Menu.Popup docs

Props
PropTypeDefaultDetails
children requiredReact.ReactNodeNo default
Base UI Menu.Popup docs
Data attributes
AttributeDescription
data-open

Present when the menu is open.

data-closed

Present when the menu is closed.

data-starting-style

Present when the menu begins animating in.

data-ending-style

Present when the menu is animating out.

data-side

Values: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

Indicates which side the popup is positioned relative to the anchor.

data-align

Values: 'start' | 'center' | 'end'

Indicates how the popup is aligned relative to specified side.

data-instant

Values: 'click' | 'dismiss' | 'group' | 'trigger-change'

Present if animations should be instant.

ContextMenuGroup

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

Base UI Menu.Group docs

ContextMenuGroupLabel

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

Base UI Menu.GroupLabel docs

ContextMenuItem

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

Base UI Menu.Item docs

Props
PropTypeDefaultDetails
variant'default' | 'destructive''default'
Base UI Menu.Item docs
Data attributes
AttributeDescription
data-variant

Values: 'default' | 'destructive'

The item variant, set by the variant prop.

data-highlighted

Present when the menu item is highlighted.

data-disabled

Present when the menu item is disabled.

ContextMenuLinkItem

A link in the menu that can be used to navigate to a different page or section. Renders an <a> element.

Base UI Menu.LinkItem docs

Props
PropTypeDefaultDetails
variant'default' | 'destructive''default'
closeOnClickbooleantrue
Base UI Menu.LinkItem docs
Data attributes
AttributeDescription
data-variant

Values: 'default' | 'destructive'

The item variant, set by the variant prop.

data-highlighted

Present when the link is highlighted.

ContextMenuPopup

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

Base UI Menu.Popup docs

Data attributes
AttributeDescription
data-open

Present when the menu is open.

data-closed

Present when the menu is closed.

data-starting-style

Present when the menu begins animating in.

data-ending-style

Present when the menu is animating out.

data-side

Values: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'

Indicates which side the popup is positioned relative to the anchor.

data-align

Values: 'start' | 'center' | 'end'

Indicates how the popup is aligned relative to specified side.

data-instant

Values: 'click' | 'dismiss' | 'group' | 'trigger-change'

Present if animations should be instant.

ContextMenuPortal

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

Base UI Menu.Portal docs

ContextMenuPositioner

Positions the context menu popup against the pointer or a custom anchor. Renders a <div> element.

Base UI ContextMenu.Positioner docs

Data attributes
AttributeDescription
data-open

Present when the menu is currently open.

data-side

Values: 'bottom' | 'inline-end' | 'inline-start' | 'left' | 'right' | 'top'

The side of the anchor the component is placed on.

data-align

Values: 'center' | 'end' | 'start'

The alignment of the component relative to the anchor.

data-anchorhidden

Present when the anchor element is hidden.

data-nested

Present when the component is nested.

data-instant

Values: string

Whether CSS transitions should be disabled.

ContextMenuRadioGroup

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

Base UI Menu.RadioGroup docs

Props
PropTypeDefaultDetails
defaultValueValueNo default
onValueChange((value: Value, eventDetails: ContextMenuRadioGroupChangeEventDetails) => void)No default
valueValueNo default
Base UI Menu.RadioGroup docs
Data attributes
AttributeDescription
data-disabled

Whether the component is disabled.

ContextMenuRadioItem

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

Base UI Menu.RadioItem docs

Props
PropTypeDefaultDetails
value requiredValueNo default
Base UI Menu.RadioItem docs
Data attributes
AttributeDescription
data-checked

Present when the menu radio item is selected.

data-unchecked

Present when the menu radio item is not selected.

data-disabled

Present when the menu radio item is disabled.

data-highlighted

Present when the menu radio item is highlighted.

ContextMenuRadioItemIndicator

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

Base UI Menu.RadioItemIndicator docs

Data attributes
AttributeDescription
data-checked

Present when the menu radio item is selected.

data-unchecked

Present when the menu radio item is not selected.

data-disabled

Present when the menu radio item is disabled.

data-starting-style

Present when the radio indicator begins animating in.

data-ending-style

Present when the radio indicator is animating out.

ContextMenuSeparator

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

Base UI Separator docs

Data attributes
AttributeDescription
data-orientation

Values: 'horizontal' | 'vertical'

Indicates the orientation of the separator.

ContextMenuSubmenu

Groups all parts of a submenu. Doesn't render its own HTML element.

Base UI Menu.SubmenuRoot docs

ContextMenuSubmenuTrigger

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

Base UI Menu.SubmenuTrigger docs

Props
PropTypeDefaultDetails
variant'default' | 'destructive''default'
Base UI Menu.SubmenuTrigger docs
Data attributes
AttributeDescription
data-variant

Values: 'default' | 'destructive'

The item variant, set by the variant prop.

data-popup-open

Present when the corresponding submenu is open.

data-highlighted

Present when the submenu trigger is highlighted.

data-disabled

Present when the submenu trigger is disabled.

ContextMenuTrigger

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

Base UI ContextMenu.Trigger docs

Data attributes
AttributeDescription
data-popup-open

Present when the corresponding context menu is open.

data-pressed

Present when the corresponding context menu is open.