Context Menu
A menu of contextual actions that opens on right-click or long press.
Right-click a row or open its menu
Usage guidelines
- Use
ContextMenuas a shortcut to actions that are also reachable from a visible control, such as aMenubehind 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 anaria-labelor atabIndex. - Keep the
Menuwith the same actions outsideContextMenu, as a sibling. AMenuinsideContextMenujoins the context menu instead of opening on its own. - Use
ContextMenuContentfor the popup at the pointer. ComposeContextMenuPortal,ContextMenuPositionerandContextMenuPopupwhen 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 theContextMenuand opens through its handle.
Anatomy
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
Submenus and settings
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.
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
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.
| Key | Action |
|---|---|
| Down arroworUp arrow | Focuses the first or last item after the menu opens, then moves focus between items. |
| HomeorEnd | Focuses the first or last item. |
| Printable characters | Focuses the next item whose label starts with the typed text. |
| EnterorSpace | Activates the focused item and closes the menu. Checkbox and radio items toggle and keep the menu open. |
| EnterorRight arrow | Opens the submenu of a focused submenu trigger and focuses its first item. |
| Left arrow | Closes the submenu and returns focus to its trigger. |
| Escape | Closes 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.
| Prop | Type | Default | Details |
|---|---|---|---|
onOpenChange | ((open: boolean, eventDetails: BaseContextMenu.Root.ChangeEventDetails) => void) | No default | |
closeParentOnEsc | boolean | No default | |
children | React.ReactNode | No default | |
defaultOpen | boolean | false | |
loopFocus | boolean | true | |
highlightItemOnHover | boolean | true | |
onOpenChangeComplete | ((open: boolean) => void) | No default | |
onItemHighlighted | ((highlightedItem: HTMLElement | undefined, eventDetails: MenuRoot.HighlightEventDetails) => void) | No default | |
open | boolean | No default | |
orientation | 'horizontal' | 'vertical' | 'vertical' | |
disabled | boolean | false | |
actionsRef | React.RefObject<MenuRootActions | null> | No default | |
ContextMenuCheckboxItem
A menu item that toggles a setting on or off. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: MenuCheckboxItemState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, MenuCheckboxItemState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: MenuCheckboxItemState) => React.CSSProperties | undefined) | No default | |
checked | boolean | No default | |
defaultChecked | boolean | false | |
onCheckedChange | ((checked: boolean, eventDetails: BaseContextMenu.CheckboxItem.ChangeEventDetails) => void) | No default | |
disabled | boolean | false | |
label | string | No default | |
id | string | No default | |
closeOnClick | boolean | false | |
nativeButton | boolean | false | |
| Attribute | Description |
|---|---|
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.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: MenuCheckboxItemIndicatorState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, MenuCheckboxItemIndicatorState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: MenuCheckboxItemIndicatorState) => React.CSSProperties | undefined) | No default | |
keepMounted | boolean | false | |
| Attribute | Description |
|---|---|
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.
| Prop | Type | Default | Details |
|---|---|---|---|
children required | React.ReactNode | No default | |
className | string | ((state: MenuPopupState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, MenuPopupState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: MenuPopupState) => React.CSSProperties | undefined) | No default | |
id | string | No default | |
finalFocus | boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | HTMLElement | null | void) | No default | |
side | 'bottom' | 'inline-end' | 'inline-start' | 'left' | 'right' | 'top' | 'bottom' | |
sideOffset | number | OffsetFunction | No default | |
align | 'center' | 'end' | 'start' | 'start' | |
alignOffset | number | OffsetFunction | No default | |
| Attribute | Description |
|---|---|
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: Indicates which side the popup is positioned relative to the anchor. |
data-align | Values: Indicates how the popup is aligned relative to specified side. |
data-instant | Values: Present if animations should be instant. |
ContextMenuGroup
Groups related menu items with the corresponding label. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
children | React.ReactNode | No default | |
className | string | ((state: MenuGroupState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, MenuGroupState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: MenuGroupState) => React.CSSProperties | undefined) | No default | |
ContextMenuGroupLabel
An accessible label that is automatically associated with its parent group. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: MenuGroupLabelState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, MenuGroupLabelState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: MenuGroupLabelState) => React.CSSProperties | undefined) | No default | |
ContextMenuItem
An individual interactive item in the menu. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
variant | 'default' | 'destructive' | 'default' | |
disabled | boolean | false | |
label | string | No default | |
id | string | No default | |
closeOnClick | boolean | true | |
className | string | ((state: MenuItemState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, MenuItemState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: MenuItemState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | false | |
| Attribute | Description |
|---|---|
data-variant | Values: The item variant, set by the |
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.
| Prop | Type | Default | Details |
|---|---|---|---|
variant | 'default' | 'destructive' | 'default' | |
closeOnClick | boolean | true | |
className | string | ((state: MenuLinkItemState) => string | undefined) | No default | |
render | ComponentRenderFn<React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, MenuLinkItemState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: MenuLinkItemState) => React.CSSProperties | undefined) | No default | |
label | string | No default | |
id | string | No default | |
| Attribute | Description |
|---|---|
data-variant | Values: The item variant, set by the |
data-highlighted | Present when the link is highlighted. |
ContextMenuPopup
A container for the menu items. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
children | React.ReactNode | No default | |
id | string | No default | |
finalFocus | boolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | HTMLElement | null | void) | No default | |
className | string | ((state: MenuPopupState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, MenuPopupState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: MenuPopupState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
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: Indicates which side the popup is positioned relative to the anchor. |
data-align | Values: Indicates how the popup is aligned relative to specified side. |
data-instant | Values: 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.
| Prop | Type | Default | Details |
|---|---|---|---|
keepMounted | boolean | false | |
container | HTMLElement | React.RefObject<HTMLElement | ShadowRoot | null> | ShadowRoot | null | No default | |
className | string | ((state: MenuPortalState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, MenuPortalState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: MenuPortalState) => React.CSSProperties | undefined) | No default | |
ContextMenuPositioner
Positions the context menu popup against the pointer or a custom anchor. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: ContextMenuPositionerState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, ContextMenuPositionerState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: ContextMenuPositionerState) => React.CSSProperties | undefined) | No default | |
anchor | Element | React.RefObject<Element | null> | VirtualElement | (() => Element | VirtualElement | null) | null | No default | |
positionMethod | 'absolute' | 'fixed' | No default | |
side | 'bottom' | 'inline-end' | 'inline-start' | 'left' | 'right' | 'top' | 'bottom' | |
sideOffset | number | OffsetFunction | No default | |
align | 'center' | 'end' | 'start' | 'start' | |
alignOffset | number | OffsetFunction | No default | |
arrowPadding | number | No default | |
collisionBoundary | Boundary | 'clipping-ancestors' | |
collisionPadding | Padding | 5 | |
sticky | boolean | false | |
disableAnchorTracking | boolean | false | |
collisionAvoidance | CollisionAvoidance | No default | |
| Attribute | Description |
|---|---|
data-open | Present when the menu is currently open. |
data-side | Values: The side of the anchor the component is placed on. |
data-align | Values: 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: Whether CSS transitions should be disabled. |
ContextMenuRadioGroup
Groups related radio items. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
defaultValue | Value | No default | |
onValueChange | ((value: Value, eventDetails: ContextMenuRadioGroupChangeEventDetails) => void) | No default | |
value | Value | No default | |
className | string | ((state: MenuRadioGroupState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, MenuRadioGroupState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: MenuRadioGroupState) => React.CSSProperties | undefined) | No default | |
children | React.ReactNode | No default | |
disabled | boolean | false | |
| Attribute | Description |
|---|---|
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.
| Prop | Type | Default | Details |
|---|---|---|---|
value required | Value | No default | |
className | string | ((state: MenuRadioItemState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, MenuRadioItemState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: MenuRadioItemState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | false | |
disabled | boolean | false | |
label | string | No default | |
id | string | No default | |
closeOnClick | boolean | false | |
| Attribute | Description |
|---|---|
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.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: MenuRadioItemIndicatorState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, MenuRadioItemIndicatorState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: MenuRadioItemIndicatorState) => React.CSSProperties | undefined) | No default | |
keepMounted | boolean | false | |
| Attribute | Description |
|---|---|
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.
| Prop | Type | Default | Details |
|---|---|---|---|
orientation | 'horizontal' | 'vertical' | 'horizontal' | |
className | string | ((state: SeparatorState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, SeparatorState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: SeparatorState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-orientation | Values: Indicates the orientation of the separator. |
ContextMenuSubmenu
Groups all parts of a submenu. Doesn't render its own HTML element.
| Prop | Type | Default | Details |
|---|---|---|---|
onOpenChange | ((open: boolean, eventDetails: BaseContextMenu.SubmenuRoot.ChangeEventDetails) => void) | No default | |
closeParentOnEsc | boolean | false | |
children | React.ReactNode | No default | |
defaultOpen | boolean | false | |
loopFocus | boolean | true | |
highlightItemOnHover | boolean | true | |
onOpenChangeComplete | ((open: boolean) => void) | No default | |
onItemHighlighted | ((highlightedItem: HTMLElement | undefined, eventDetails: MenuRoot.HighlightEventDetails) => void) | No default | |
open | boolean | No default | |
orientation | 'horizontal' | 'vertical' | 'vertical' | |
disabled | boolean | false | |
actionsRef | React.RefObject<MenuRootActions | null> | No default | |
ContextMenuSubmenuTrigger
A menu item that opens a submenu. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
variant | 'default' | 'destructive' | 'default' | |
className | string | ((state: MenuSubmenuTriggerState) => string | undefined) | No default | |
label | string | No default | |
id | string | No default | |
disabled | boolean | false | |
delay | number | 100 | |
closeDelay | number | 0 | |
openOnHover | boolean | true | |
render | ComponentRenderFn<HTMLProps, MenuSubmenuTriggerState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: MenuSubmenuTriggerState) => React.CSSProperties | undefined) | No default | |
nativeButton | boolean | false | |
| Attribute | Description |
|---|---|
data-variant | Values: The item variant, set by the |
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.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: ContextMenuTriggerState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, ContextMenuTriggerState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: ContextMenuTriggerState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-popup-open | Present when the corresponding context menu is open. |
data-pressed | Present when the corresponding context menu is open. |