Context Menu
A menu that appears at the pointer on right click or long press.
View as MarkdownAnatomy
Import the components and place them together:
import { ContextMenu } from '@base-ui/react/context-menu';
<ContextMenu.Root>
<ContextMenu.Trigger />
<ContextMenu.Portal>
<ContextMenu.Backdrop />
<ContextMenu.Positioner>
<ContextMenu.Popup>
<ContextMenu.Arrow />
<ContextMenu.Item />
<ContextMenu.LinkItem />
<ContextMenu.Separator />
<ContextMenu.Group>
<ContextMenu.GroupLabel />
</ContextMenu.Group>
<ContextMenu.RadioGroup>
<ContextMenu.RadioItem />
</ContextMenu.RadioGroup>
<ContextMenu.CheckboxItem />
<ContextMenu.SubmenuRoot>
<ContextMenu.SubmenuTrigger />
</ContextMenu.SubmenuRoot>
</ContextMenu.Popup>
</ContextMenu.Positioner>
</ContextMenu.Portal>
</ContextMenu.Root>Examples
Menu displays additional demos, many of which apply to the context menu as well.
Nested menu
To create a submenu, create a <ContextMenu.SubmenuRoot> inside the parent context menu. Use the <ContextMenu.SubmenuTrigger> part for the menu item that opens the nested menu.
API reference
Root
A component that creates a context menu activated by right clicking or long pressing. Doesn’t render its own HTML element.
defaultOpenbooleanfalse
- Name
- Description
Whether the menu is initially open.
To render a controlled menu, use the
openprop instead.- Type
boolean | undefined- Default
false
openboolean—
- Name
- Description
Whether the menu is currently open.
- Type
boolean | undefined
onOpenChangefunction—
- Name
- Description
Event handler called when the menu is opened or closed.
- Type
| (( open: boolean, eventDetails: ContextMenu.Root.ChangeEventDetails, ) => void) | undefined
highlightItemOnHoverbooleantrue
- Description
Whether moving the pointer over items should highlight them. Disabling this prop allows CSS
:hoverto be differentiated from the:focus(data-highlighted) state.- Type
boolean | undefined- Default
true
actionsRefReact.RefObject<MenuRoot.Actions | null>—
- Name
- Description
A ref to imperative actions.
unmount: When specified, the menu will not be unmounted when closed. Instead, theunmountfunction must be called to unmount the menu manually. Useful when the menu’s animation is controlled by an external library.close: When specified, the menu can be closed imperatively.
- Type
| React.RefObject<MenuRoot.Actions | null> | undefined
closeParentOnEscbooleanfalse
- Name
- Description
When in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu.
- Type
boolean | undefined- Default
false
defaultTriggerIdstring | null—
- Name
- Description
ID of the trigger that the popover is associated with. This is useful in conjunction with the
defaultOpenprop to create an initially open popover.- Type
string | null | undefined
handleMenuHandle<unknown>—
- Name
- Description
A handle to associate the menu with a trigger. If specified, allows external triggers to control the menu’s open state.
- Type
MenuHandle<unknown> | undefined
loopFocusbooleantrue
- Name
- Description
Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.
- Type
boolean | undefined- Default
true
onOpenChangeCompletefunction—
- Description
Event handler called after any animations complete when the menu is closed.
- Type
((open: boolean) => void) | undefined
triggerIdstring | null—
- Name
- Description
ID of the trigger that the popover is associated with. This is useful in conjunction with the
openprop to create a controlled popover. There’s no need to specify this prop when the popover is uncontrolled (that is, when theopenprop is not set).- Type
string | null | undefined
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
orientationMenuRoot.Orientation'vertical'
- Name
- Description
The visual orientation of the menu. Controls whether roving focus uses up/down or left/right arrow keys.
- Type
MenuRoot.Orientation | undefined- Default
'vertical'
children| React.ReactNode
| PayloadChildRenderFunction<unknown>—
| PayloadChildRenderFunction<unknown>
- Name
- Description
The content of the popover. This can be a regular React node or a render function that receives the
payloadof the active trigger.- Type
React.ReactNode | ((arg: { payload: unknown }) => ReactNode)<unknown> | undefined
ContextMenu.Root.StateHide
type ContextMenuRootState = {}ContextMenu.Root.ActionsHide
type ContextMenuRootActions = { unmount: () => void; close: () => void }ContextMenu.Root.ChangeEventReasonHide
type ContextMenuRootChangeEventReason =
| 'trigger-hover'
| 'trigger-focus'
| 'trigger-press'
| 'outside-press'
| 'focus-out'
| 'list-navigation'
| 'escape-key'
| 'item-press'
| 'close-press'
| 'sibling-open'
| 'cancel-open'
| 'imperative-action'
| 'none'ContextMenu.Root.ChangeEventDetailsHide
type ContextMenuRootChangeEventDetails = (
| { reason: 'trigger-hover'; event: MouseEvent }
| { reason: 'trigger-focus'; event: FocusEvent }
| { reason: 'trigger-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
| { reason: 'outside-press'; event: MouseEvent | PointerEvent | TouchEvent }
| { reason: 'focus-out'; event: FocusEvent | KeyboardEvent }
| { reason: 'list-navigation'; event: KeyboardEvent }
| { reason: 'escape-key'; event: KeyboardEvent }
| { reason: 'item-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'close-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'sibling-open'; event: Event }
| { reason: 'cancel-open'; event: MouseEvent }
| { reason: 'imperative-action'; event: Event }
| { reason: 'none'; event: Event }
) & {
/** Cancels Base UI from handling the event. */
cancel: () => void;
/** Allows the event to propagate in cases where Base UI will stop the propagation. */
allowPropagation: () => void;
/** Indicates whether the event has been canceled. */
isCanceled: boolean;
/** Indicates whether the event is allowed to propagate. */
isPropagationAllowed: boolean;
/** The element that triggered the event, if applicable. */
trigger: Element | undefined;
}Trigger
An area that opens the menu on right click or long press.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: ContextMenu.Trigger.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.Trigger.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.Trigger.State, ) => ReactElement) | undefined
data-popup-open
Present when the corresponding context menu is open.
data-pressed
Present when the trigger is pressed.
| Attribute | Description | |
|---|---|---|
data-popup-open | Present when the corresponding context menu is open. | |
data-pressed | Present when the trigger is pressed. | |
ContextMenu.Trigger.StateHide
type ContextMenuTriggerState = {
/** Whether the context menu is currently open. */
open: boolean;
}Portal
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.
containerUnion—
- Name
- Description
A parent element to render the portal element into.
- Type
| HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null | undefined
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: ContextMenu.Portal.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.Portal.State, ) => React.CSSProperties | undefined) | undefined
keepMountedbooleanfalse
- Name
- Description
Whether to keep the portal mounted in the DOM while the popup is hidden.
- Type
boolean | undefined- Default
false
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.Portal.State, ) => ReactElement) | undefined
ContextMenu.Portal.StateHide
type ContextMenuPortalState = {}Positioner
Positions the menu popup against the trigger.
Renders a <div> element.
disableAnchorTrackingbooleanfalse
- Description
Whether to disable the popup from tracking any layout shift of its positioning anchor.
- Type
boolean | undefined- Default
false
alignAlign'center'
- Name
- Description
How to align the popup relative to the specified side.
- Type
'start' | 'center' | 'end' | undefined- Default
'center'
alignOffsetnumber | OffsetFunction0
- Name
- Description
Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment.
The function takes a
dataobject parameter with the following properties:data.anchor: the dimensions of the anchor element with propertieswidthandheight.data.positioner: the dimensions of the positioner element with propertieswidthandheight.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.
- Type
| number | ((data: { side: | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'; align: 'start' | 'center' | 'end'; anchor: { width: number; height: number }; positioner: { width: number; height: number }; }) => number) | undefined- Default
0- Example
<Positioner alignOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.width : anchor.height; }} />
sideSide'bottom'
- Name
- Description
Which side of the anchor element to align the popup against. May automatically change to avoid collisions.
- Type
| 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start' | undefined- Default
'bottom'
sideOffsetnumber | OffsetFunction0
- Name
- Description
Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment.
The function takes a
dataobject parameter with the following properties:data.anchor: the dimensions of the anchor element with propertieswidthandheight.data.positioner: the dimensions of the positioner element with propertieswidthandheight.data.side: which side of the anchor element the positioner is aligned against.data.align: how the positioner is aligned relative to the specified side.
- Type
| number | ((data: { side: | 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'; align: 'start' | 'center' | 'end'; anchor: { width: number; height: number }; positioner: { width: number; height: number }; }) => number) | undefined- Default
0- Example
<Positioner sideOffset={({ side, align, anchor, positioner }) => { return side === 'top' || side === 'bottom' ? anchor.height : anchor.width; }} />
arrowPaddingnumber5
- Name
- Description
Minimum distance to maintain between the arrow and the edges of the popup.
Use it to prevent the arrow element from hanging out of the rounded corners of a popup.
- Type
number | undefined- Default
5
anchorUnion—
- Name
- Description
An element to position the popup against. By default, the popup will be positioned against the trigger.
- Type
| Element | VirtualElement | React.RefObject<Element | null> | (() => Element | VirtualElement | null) | null | undefined
collisionAvoidanceCollisionAvoidance—
- Description
Determines how to handle collisions when positioning the popup.
sidecontrols overflow on the preferred placement axis (top/bottomorleft/right):'flip': keep the requested side when it fits; otherwise try the opposite side (topandbottom, orleftandright).'shift': never change side; keep the requested side and move the popup within the clipping boundary so it stays visible.'none': do not correct side-axis overflow.
aligncontrols overflow on the alignment axis (start/center/end):'flip': keep side, but swapstartandendwhen the requested alignment overflows.'shift': keep side and requested alignment, then nudge the popup along the alignment axis to fit.'none': do not correct alignment-axis overflow.
fallbackAxisSidecontrols fallback behavior on the perpendicular axis when the preferred axis cannot fit:'start': allow perpendicular fallback and try the logical start side first (topbeforebottom, orleftbeforerightin LTR).'end': allow perpendicular fallback and try the logical end side first (bottombeforetop, orrightbeforeleftin LTR).'none': do not fallback to the perpendicular axis.
When
sideis'shift', explicitly settingalignonly supports'shift'or'none'. Ifalignis omitted, it defaults to'flip'.- Type
CollisionAvoidance | undefined- Example
<Positioner collisionAvoidance={{ side: 'shift', align: 'shift', fallbackAxisSide: 'none', }} />
collisionBoundaryBoundary'clipping-ancestors'
- Description
An element or a rectangle that delimits the area that the popup is confined to.
- Type
Boundary | undefined- Default
'clipping-ancestors'
collisionPaddingPadding5
- Name
- Description
Additional space to maintain from the edge of the collision boundary.
- Type
Padding | undefined- Default
5
stickybooleanfalse
- Name
- Description
Whether to maintain the popup in the viewport after the anchor element was scrolled out of view.
- Type
boolean | undefined- Default
false
positionMethod'absolute' | 'fixed''absolute'
- Name
- Description
Determines which CSS
positionproperty to use.- Type
'absolute' | 'fixed' | undefined- Default
'absolute'
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: ContextMenu.Positioner.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.Positioner.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.Positioner.State, ) => ReactElement) | undefined
data-open
Present when the menu popup is open.
data-closed
Present when the menu popup is closed.
data-anchor-hidden
Present when the anchor is hidden.
data-align
Indicates how the popup is aligned relative to specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.
| Attribute | Description | |
|---|---|---|
data-open | Present when the menu popup is open. | |
data-closed | Present when the menu popup is closed. | |
data-anchor-hidden | Present when the anchor is hidden. | |
data-align | Indicates how the popup is aligned relative to specified side. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
--anchor-height
The anchor’s height.
--anchor-width
The anchor’s width.
--available-height
The available height between the trigger and the edge of the viewport.
--available-width
The available width between the trigger and the edge of the viewport.
--transform-origin
The coordinates that this element is anchored to. Used for animations and transitions.
| CSS Variable | Description | |
|---|---|---|
--anchor-height | The anchor’s height. | |
--anchor-width | The anchor’s width. | |
--available-height | The available height between the trigger and the edge of the viewport. | |
--available-width | The available width between the trigger and the edge of the viewport. | |
--transform-origin | The coordinates that this element is anchored to. Used for animations and transitions. | |
ContextMenu.Positioner.PropsHide
Re-Export of Positioner props as ContextMenuPositionerProps
ContextMenu.Positioner.StateHide
type ContextMenuPositionerState = {
/** Whether the menu is currently open. */
open: boolean;
/** The side of the anchor the component is placed on. */
side: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start';
/** The alignment of the component relative to the anchor. */
align: 'start' | 'center' | 'end';
/** Whether the anchor element is hidden. */
anchorHidden: boolean;
/** Whether the component is nested. */
nested: boolean;
/** Whether CSS transitions should be disabled. */
instant: string | undefined;
}Popup
A container for the menu items.
Renders a <div> element.
finalFocusUnion—
- Name
- Description
Determines the element to focus when the menu is closed.
false: Do not move focus.true: Move focus based on the default behavior (trigger or previously focused element).RefObject: Move focus to the ref element.function: Called with the interaction type (mouse,touch,pen, orkeyboard). Return an element to focus,trueto use the default behavior, orfalse/undefinedto do nothing.
- Type
| boolean | React.RefObject<HTMLElement | null> | (( closeType: | 'mouse' | 'touch' | 'pen' | 'keyboard' | '', ) => boolean | void | HTMLElement | null) | undefined
childrenReact.ReactNode—
- Name
- Type
React.ReactNode | undefined
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: ContextMenu.Popup.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.Popup.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.Popup.State, ) => ReactElement) | undefined
data-open
Present when the menu is open.
data-closed
Present when the menu is closed.
data-align
Indicates how the popup is aligned relative to specified side.
data-instant
Present if animations should be instant.
data-side
Indicates which side the popup is positioned relative to the trigger.
data-starting-style
Present when the menu is animating in.
data-ending-style
Present when the menu is animating out.
| Attribute | Description | |
|---|---|---|
data-open | Present when the menu is open. | |
data-closed | Present when the menu is closed. | |
data-align | Indicates how the popup is aligned relative to specified side. | |
data-instant | Present if animations should be instant. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
data-starting-style | Present when the menu is animating in. | |
data-ending-style | Present when the menu is animating out. | |
ContextMenu.Popup.StateHide
type ContextMenuPopupState = {
/** The transition status of the component. */
transitionStatus: TransitionStatus;
/** The side of the anchor the component is placed on. */
side: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start';
/** The alignment of the component relative to the anchor. */
align: 'start' | 'center' | 'end';
/** Whether the menu is currently open. */
open: boolean;
/** Whether the component is nested. */
nested: boolean;
/** Whether transitions should be skipped. */
instant: 'dismiss' | 'click' | 'group' | 'trigger-change' | undefined;
}Arrow
Displays an element positioned against the menu anchor.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: ContextMenu.Arrow.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.Arrow.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.Arrow.State, ) => ReactElement) | undefined
data-open
Present when the menu popup is open.
data-closed
Present when the menu popup is closed.
data-uncentered
Present when the menu arrow is uncentered.
data-align
Indicates how the popup is aligned relative to specified side.
data-side
Indicates which side the popup is positioned relative to the trigger.
| Attribute | Description | |
|---|---|---|
data-open | Present when the menu popup is open. | |
data-closed | Present when the menu popup is closed. | |
data-uncentered | Present when the menu arrow is uncentered. | |
data-align | Indicates how the popup is aligned relative to specified side. | |
data-side | Indicates which side the popup is positioned relative to the trigger. | |
ContextMenu.Arrow.StateHide
type ContextMenuArrowState = {
/** Whether the menu is currently open. */
open: boolean;
/** The side of the anchor the component is placed on. */
side: 'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start';
/** The alignment of the component relative to the anchor. */
align: 'start' | 'center' | 'end';
/** Whether the arrow cannot be centered on the anchor. */
uncentered: boolean;
}Item
An individual interactive item in the menu.
Renders a <div> element.
labelstring—
- Name
- Description
Overrides the text label to use when the item is matched during keyboard text navigation.
- Type
string | undefined
onClickfunction—
- Name
- Description
The click handler for the menu item.
- Type
| (( event: BaseUIEvent< React.MouseEvent<HTMLDivElement, MouseEvent> >, ) => void) | undefined
closeOnClickbooleantrue
- Name
- Description
Whether to close the menu when the item is clicked.
- Type
boolean | undefined- Default
true
nativeButtonbooleanfalse
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set totrueif the rendered element is a native button.- Type
boolean | undefined- Default
false
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: ContextMenu.Item.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.Item.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.Item.State, ) => ReactElement) | undefined
data-highlighted
Present when the menu item is highlighted.
data-disabled
Present when the menu item is disabled.
| Attribute | Description | |
|---|---|---|
data-highlighted | Present when the menu item is highlighted. | |
data-disabled | Present when the menu item is disabled. | |
ContextMenu.Item.StateHide
type ContextMenuItemState = {
/** Whether the item should ignore user interaction. */
disabled: boolean;
/** Whether the item is highlighted. */
highlighted: boolean;
}LinkItem
A link in the menu that can be used to navigate to a different page or section.
Renders an <a> element.
labelstring—
- Name
- Description
Overrides the text label to use when the item is matched during keyboard text navigation.
- Type
string | undefined
closeOnClickbooleanfalse
- Name
- Description
Whether to close the menu when the item is clicked.
- Type
boolean | undefined- Default
false
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: ContextMenu.LinkItem.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.LinkItem.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.LinkItem.State, ) => ReactElement) | undefined
data-highlighted
Present when the link is highlighted.
| Attribute | Description | |
|---|---|---|
data-highlighted | Present when the link is highlighted. | |
ContextMenu.LinkItem.StateHide
type ContextMenuLinkItemState = {
/** Whether the item is highlighted. */
highlighted: boolean;
}SubmenuRoot
Groups all parts of a submenu. Doesn’t render its own HTML element.
defaultOpenbooleanfalse
- Name
- Description
Whether the menu is initially open.
To render a controlled menu, use the
openprop instead.- Type
boolean | undefined- Default
false
openboolean—
- Name
- Description
Whether the menu is currently open.
- Type
boolean | undefined
onOpenChangefunction—
- Name
- Description
Event handler called when the menu is opened or closed.
- Type
| (( open: boolean, eventDetails: ContextMenu.SubmenuRoot.ChangeEventDetails, ) => void) | undefined
highlightItemOnHoverbooleantrue
- Description
Whether moving the pointer over items should highlight them. Disabling this prop allows CSS
:hoverto be differentiated from the:focus(data-highlighted) state.- Type
boolean | undefined- Default
true
actionsRefReact.RefObject<MenuRoot.Actions | null>—
- Name
- Description
A ref to imperative actions.
unmount: When specified, the menu will not be unmounted when closed. Instead, theunmountfunction must be called to unmount the menu manually. Useful when the menu’s animation is controlled by an external library.close: When specified, the menu can be closed imperatively.
- Type
| React.RefObject<MenuRoot.Actions | null> | undefined
closeParentOnEscbooleanfalse
- Name
- Description
When in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu.
- Type
boolean | undefined- Default
false
defaultTriggerIdstring | null—
- Name
- Description
ID of the trigger that the popover is associated with. This is useful in conjunction with the
defaultOpenprop to create an initially open popover.- Type
string | null | undefined
handleMenuHandle<unknown>—
- Name
- Description
A handle to associate the menu with a trigger. If specified, allows external triggers to control the menu’s open state.
- Type
MenuHandle<unknown> | undefined
loopFocusbooleantrue
- Name
- Description
Whether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.
- Type
boolean | undefined- Default
true
onOpenChangeCompletefunction—
- Description
Event handler called after any animations complete when the menu is closed.
- Type
((open: boolean) => void) | undefined
triggerIdstring | null—
- Name
- Description
ID of the trigger that the popover is associated with. This is useful in conjunction with the
openprop to create a controlled popover. There’s no need to specify this prop when the popover is uncontrolled (that is, when theopenprop is not set).- Type
string | null | undefined
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
orientationMenuRoot.Orientation'vertical'
- Name
- Description
The visual orientation of the menu. Controls whether roving focus uses up/down or left/right arrow keys.
- Type
MenuRoot.Orientation | undefined- Default
'vertical'
children| React.ReactNode
| PayloadChildRenderFunction<unknown>—
| PayloadChildRenderFunction<unknown>
- Name
- Description
The content of the popover. This can be a regular React node or a render function that receives the
payloadof the active trigger.- Type
React.ReactNode | ((arg: { payload: unknown }) => ReactNode)<unknown> | undefined
SubmenuTrigger
A menu item that opens a submenu.
Renders a <div> element.
labelstring—
- Name
- Description
Overrides the text label to use when the item is matched during keyboard text navigation.
- Type
string | undefined
onClickfunction—
- Name
- Type
| (( event: BaseUIEvent< React.MouseEvent<HTMLDivElement, MouseEvent> >, ) => void) | undefined
nativeButtonbooleanfalse
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set totrueif the rendered element is a native button.- Type
boolean | undefined- Default
false
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
openOnHoverboolean—
- Name
- Description
Whether the menu should also open when the trigger is hovered.
- Type
boolean | undefined
delaynumber100
- Name
- Description
How long to wait before the menu may be opened on hover. Specified in milliseconds.
Requires the
openOnHoverprop.- Type
number | undefined- Default
100
closeDelaynumber0
- Name
- Description
How long to wait before closing the menu that was opened on hover. Specified in milliseconds.
Requires the
openOnHoverprop.- Type
number | undefined- Default
0
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: ContextMenu.SubmenuTrigger.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.SubmenuTrigger.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.SubmenuTrigger.State, ) => ReactElement) | undefined
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.
| Attribute | Description | |
|---|---|---|
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. | |
Group
Groups related menu items with the corresponding label.
Renders a <div> element.
childrenReact.ReactNode—
- Name
- Description
The content of the component.
- Type
React.ReactNode | undefined
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: ContextMenu.Group.State) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.Group.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.Group.State, ) => ReactElement) | undefined
ContextMenu.Group.StateHide
type ContextMenuGroupState = {}GroupLabel
An accessible label that is automatically associated with its parent group.
Renders a <div> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: ContextMenu.GroupLabel.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.GroupLabel.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.GroupLabel.State, ) => ReactElement) | undefined
ContextMenu.GroupLabel.PropsHide
Re-Export of GroupLabel props as ContextMenuGroupLabelProps
ContextMenu.GroupLabel.StateHide
type ContextMenuGroupLabelState = {}RadioGroup
Groups related radio items.
Renders a <div> element.
defaultValueany—
- Name
- Description
The uncontrolled value of the radio item that should be initially selected.
To render a controlled radio group, use the
valueprop instead.- Type
any | undefined
valueany—
- Name
- Description
The controlled value of the radio item that should be currently selected.
To render an uncontrolled radio group, use the
defaultValueprop instead.- Type
any | undefined
onValueChangefunction—
- Name
- Description
Function called when the selected value changes.
- Type
| (( value: any, eventDetails: ContextMenu.RadioGroup.ChangeEventDetails, ) => void) | undefined
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
childrenReact.ReactNode—
- Name
- Description
The content of the component.
- Type
React.ReactNode | undefined
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: ContextMenu.RadioGroup.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.RadioGroup.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.RadioGroup.State, ) => ReactElement) | undefined
ContextMenu.RadioGroup.PropsHide
Re-Export of RadioGroup props as ContextMenuRadioGroupProps
ContextMenu.RadioGroup.StateHide
type ContextMenuRadioGroupState = {
/** Whether the component is disabled. */
disabled: boolean;
}ContextMenu.RadioGroup.ChangeEventReasonHide
type ContextMenuRadioGroupChangeEventReason =
| 'trigger-hover'
| 'trigger-focus'
| 'trigger-press'
| 'outside-press'
| 'focus-out'
| 'list-navigation'
| 'escape-key'
| 'item-press'
| 'close-press'
| 'sibling-open'
| 'cancel-open'
| 'imperative-action'
| 'none'ContextMenu.RadioGroup.ChangeEventDetailsHide
type ContextMenuRadioGroupChangeEventDetails = (
| { reason: 'trigger-hover'; event: MouseEvent }
| { reason: 'trigger-focus'; event: FocusEvent }
| { reason: 'trigger-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
| { reason: 'outside-press'; event: MouseEvent | PointerEvent | TouchEvent }
| { reason: 'focus-out'; event: FocusEvent | KeyboardEvent }
| { reason: 'list-navigation'; event: KeyboardEvent }
| { reason: 'escape-key'; event: KeyboardEvent }
| { reason: 'item-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'close-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'sibling-open'; event: Event }
| { reason: 'cancel-open'; event: MouseEvent }
| { reason: 'imperative-action'; event: Event }
| { reason: 'none'; event: Event }
) & {
/** Cancels Base UI from handling the event. */
cancel: () => void;
/** Allows the event to propagate in cases where Base UI will stop the propagation. */
allowPropagation: () => void;
/** Indicates whether the event has been canceled. */
isCanceled: boolean;
/** Indicates whether the event is allowed to propagate. */
isPropagationAllowed: boolean;
/** The element that triggered the event, if applicable. */
trigger: Element | undefined;
preventUnmountOnClose: (() => void);
}RadioItem
A menu item that works like a radio button in a given group.
Renders a <div> element.
labelstring—
- Name
- Description
Overrides the text label to use when the item is matched during keyboard text navigation.
- Type
string | undefined
value*any
—
any- Name
- Description
Value of the radio item. This is the value that will be set in the ContextMenu.RadioGroup when the item is selected.
- Type
any
onClickfunction—
- Name
- Description
The click handler for the menu item.
- Type
| (( event: BaseUIEvent< React.MouseEvent<HTMLDivElement, MouseEvent> >, ) => void) | undefined
closeOnClickbooleanfalse
- Name
- Description
Whether to close the menu when the item is clicked.
- Type
boolean | undefined- Default
false
nativeButtonbooleanfalse
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set totrueif the rendered element is a native button.- Type
boolean | undefined- Default
false
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: ContextMenu.RadioItem.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.RadioItem.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.RadioItem.State, ) => ReactElement) | undefined
data-checked
Present when the menu radio item is selected.
data-unchecked
Present when the menu radio item is not selected.
data-highlighted
Present when the menu radio item is highlighted.
data-disabled
Present when the menu radio item is disabled.
| Attribute | Description | |
|---|---|---|
data-checked | Present when the menu radio item is selected. | |
data-unchecked | Present when the menu radio item is not selected. | |
data-highlighted | Present when the menu radio item is highlighted. | |
data-disabled | Present when the menu radio item is disabled. | |
ContextMenu.RadioItem.StateHide
type ContextMenuRadioItemState = {
/** Whether the radio item should ignore user interaction. */
disabled: boolean;
/** Whether the radio item is currently highlighted. */
highlighted: boolean;
/** Whether the radio item is currently selected. */
checked: boolean;
}RadioItemIndicator
Indicates whether the radio item is selected.
Renders a <span> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: ContextMenu.RadioItemIndicator.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.RadioItemIndicator.State, ) => React.CSSProperties | undefined) | undefined
keepMountedbooleanfalse
- Name
- Description
Whether to keep the HTML element in the DOM when the radio item is inactive.
- Type
boolean | undefined- Default
false
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.RadioItemIndicator.State, ) => ReactElement) | undefined
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 is animating in.
data-ending-style
Present when the radio indicator is animating out.
| 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 is animating in. | |
data-ending-style | Present when the radio indicator is animating out. | |
ContextMenu.RadioItemIndicator.PropsHide
Re-Export of RadioItemIndicator props as ContextMenuRadioItemIndicatorProps
ContextMenu.RadioItemIndicator.StateHide
type ContextMenuRadioItemIndicatorState = {
/** Whether the radio item is currently selected. */
checked: boolean;
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Whether the item is highlighted. */
highlighted: boolean;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
}CheckboxItem
A menu item that toggles a setting on or off.
Renders a <div> element.
labelstring—
- Name
- Description
Overrides the text label to use when the item is matched during keyboard text navigation.
- Type
string | undefined
defaultCheckedbooleanfalse
- Name
- Description
Whether the checkbox item is initially ticked.
To render a controlled checkbox item, use the
checkedprop instead.- Type
boolean | undefined- Default
false
checkedboolean—
- Name
- Description
Whether the checkbox item is currently ticked.
To render an uncontrolled checkbox item, use the
defaultCheckedprop instead.- Type
boolean | undefined
onCheckedChangefunction—
- Name
- Description
Event handler called when the checkbox item is ticked or unticked.
- Type
| (( checked: boolean, eventDetails: ContextMenu.CheckboxItem.ChangeEventDetails, ) => void) | undefined
onClickfunction—
- Name
- Description
The click handler for the menu item.
- Type
| (( event: BaseUIEvent< React.MouseEvent<HTMLDivElement, MouseEvent> >, ) => void) | undefined
closeOnClickbooleanfalse
- Name
- Description
Whether to close the menu when the item is clicked.
- Type
boolean | undefined- Default
false
nativeButtonbooleanfalse
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set totrueif the rendered element is a native button.- Type
boolean | undefined- Default
false
disabledbooleanfalse
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: ContextMenu.CheckboxItem.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.CheckboxItem.State, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.CheckboxItem.State, ) => ReactElement) | undefined
data-checked
Present when the menu checkbox item is checked.
data-unchecked
Present when the menu checkbox item is not checked.
data-highlighted
Present when the menu checkbox item is highlighted.
data-disabled
Present when the menu checkbox item is disabled.
| Attribute | Description | |
|---|---|---|
data-checked | Present when the menu checkbox item is checked. | |
data-unchecked | Present when the menu checkbox item is not checked. | |
data-highlighted | Present when the menu checkbox item is highlighted. | |
data-disabled | Present when the menu checkbox item is disabled. | |
ContextMenu.CheckboxItem.PropsHide
Re-Export of CheckboxItem props as ContextMenuCheckboxItemProps
ContextMenu.CheckboxItem.StateHide
type ContextMenuCheckboxItemState = {
/** Whether the checkbox item should ignore user interaction. */
disabled: boolean;
/** Whether the checkbox item is currently highlighted. */
highlighted: boolean;
/** Whether the checkbox item is currently ticked. */
checked: boolean;
}ContextMenu.CheckboxItem.ChangeEventReasonHide
type ContextMenuCheckboxItemChangeEventReason =
| 'trigger-hover'
| 'trigger-focus'
| 'trigger-press'
| 'outside-press'
| 'focus-out'
| 'list-navigation'
| 'escape-key'
| 'item-press'
| 'close-press'
| 'sibling-open'
| 'cancel-open'
| 'imperative-action'
| 'none'ContextMenu.CheckboxItem.ChangeEventDetailsHide
type ContextMenuCheckboxItemChangeEventDetails = (
| { reason: 'trigger-hover'; event: MouseEvent }
| { reason: 'trigger-focus'; event: FocusEvent }
| { reason: 'trigger-press'; event: MouseEvent | PointerEvent | TouchEvent | KeyboardEvent }
| { reason: 'outside-press'; event: MouseEvent | PointerEvent | TouchEvent }
| { reason: 'focus-out'; event: FocusEvent | KeyboardEvent }
| { reason: 'list-navigation'; event: KeyboardEvent }
| { reason: 'escape-key'; event: KeyboardEvent }
| { reason: 'item-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'close-press'; event: MouseEvent | PointerEvent | KeyboardEvent }
| { reason: 'sibling-open'; event: Event }
| { reason: 'cancel-open'; event: MouseEvent }
| { reason: 'imperative-action'; event: Event }
| { reason: 'none'; event: Event }
) & {
/** Cancels Base UI from handling the event. */
cancel: () => void;
/** Allows the event to propagate in cases where Base UI will stop the propagation. */
allowPropagation: () => void;
/** Indicates whether the event has been canceled. */
isCanceled: boolean;
/** Indicates whether the event is allowed to propagate. */
isPropagationAllowed: boolean;
/** The element that triggered the event, if applicable. */
trigger: Element | undefined;
preventUnmountOnClose: (() => void);
}CheckboxItemIndicator
Indicates whether the checkbox item is ticked.
Renders a <span> element.
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | (( state: ContextMenu.CheckboxItemIndicator.State, ) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: ContextMenu.CheckboxItemIndicator.State, ) => React.CSSProperties | undefined) | undefined
keepMountedbooleanfalse
- Name
- Description
Whether to keep the HTML element in the DOM when the checkbox item is not checked.
- Type
boolean | undefined- Default
false
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: ContextMenu.CheckboxItemIndicator.State, ) => ReactElement) | undefined
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 is animating in.
data-ending-style
Present when the indicator is animating out.
| 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 is animating in. | |
data-ending-style | Present when the indicator is animating out. | |
ContextMenu.CheckboxItemIndicator.PropsHide
Re-Export of CheckboxItemIndicator props as ContextMenuCheckboxItemIndicatorProps
ContextMenu.CheckboxItemIndicator.StateHide
type ContextMenuCheckboxItemIndicatorState = {
/** Whether the checkbox item is currently ticked. */
checked: boolean;
/** Whether the component should ignore user interaction. */
disabled: boolean;
/** Whether the item is highlighted. */
highlighted: boolean;
/** The transition status of the component. */
transitionStatus: TransitionStatus;
}Separator
A separator element accessible to screen readers.
Renders a <div> element.
orientationOrientation'horizontal'
- Name
- Description
The orientation of the separator.
- Type
'horizontal' | 'vertical' | undefined- Default
'horizontal'
classNamestring | function—
- Name
- Description
CSS class applied to the element, or a function that returns a class based on the component’s state.
- Type
| string | ((state: SeparatorState) => string | undefined) | undefined
styleReact.CSSProperties | function—
- Name
- Type
| React.CSSProperties | (( state: SeparatorState, ) => React.CSSProperties | undefined) | undefined
renderReactElement | function—
- Name
- Description
Allows you to replace the component’s HTML element with a different tag, or compose it with another component.
Accepts a
ReactElementor a function that returns the element to render.- Type
| ReactElement | (( props: HTMLProps, state: SeparatorState, ) => ReactElement) | undefined
ContextMenu.Separator.StateHide
type ContextMenuSeparatorState = {
/** The orientation of the separator. */
orientation: 'horizontal' | 'vertical';
}