Menu
A list of actions in a dropdown, enhanced with keyboard navigation.
View as MarkdownAnatomy
Import the component and assemble its parts:
import { Menu } from '@base-ui-components/react/menu';
<Menu.Root>
<Menu.Trigger />
<Menu.Portal>
<Menu.Backdrop />
<Menu.Positioner>
<Menu.Popup>
<Menu.Arrow />
<Menu.Item />
<Menu.Separator />
<Menu.Group>
<Menu.GroupLabel />
</Menu.Group>
<Menu.RadioGroup>
<Menu.RadioItem />
</Menu.RadioGroup>
<Menu.CheckboxItem />
<Menu.SubmenuRoot>
<Menu.SubmenuTrigger />
</Menu.SubmenuRoot>
</Menu.Popup>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>API reference
Root
Groups all parts of the menu. Doesn’t render its own HTML element.
defaultOpenboolean
false
defaultOpenboolean
false
- Name
- Description
Whether the menu is initially open.
To render a controlled menu, use the
openprop instead.- Type
boolean | undefined- Default
false
openboolean
—
openboolean
—- Name
- Description
Whether the menu is currently open.
- Type
boolean | undefined
onOpenChangefunction
—
onOpenChangefunction
—- Name
- Description
Event handler called when the menu is opened or closed.
- Type
| (( open: boolean, eventDetails: Menu.Root.ChangeEventDetails, ) => void) | undefined
actionsRefRefObject<Menu.Root.Actions>
—
actionsRefRefObject<Menu.Root.Actions>
—- 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.
- Type
React.RefObject<Menu.Root.Actions> | undefined
closeParentOnEscboolean
true
closeParentOnEscboolean
true
- 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
true
modalboolean
true
modalboolean
true
- Name
- Description
Determines if the menu enters a modal state when open.
true: user interaction is limited to the menu: document page scroll is locked and and pointer interactions on outside elements are disabled.false: user interaction with the rest of the document is allowed.
- Type
boolean | undefined- Default
true
onOpenChangeCompletefunction
—
onOpenChangeCompletefunction
—- Description
Event handler called after any animations complete when the menu is closed.
- Type
((open: boolean) => void) | undefined
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
openOnHoverboolean
—
openOnHoverboolean
—- Name
- Description
Whether the menu should also open when the trigger is hovered.
- Type
boolean | undefined
delaynumber
100
delaynumber
100
- 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
closeDelaynumber
0
closeDelaynumber
0
- 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
loopboolean
true
loopboolean
true
- 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
orientationMenu.Root.Orientation
'vertical'
orientationMenu.Root.Orientation
'vertical'
- Name
- Description
The visual orientation of the menu. Controls whether roving focus uses up/down or left/right arrow keys.
- Type
'horizontal' | 'vertical' | undefined- Default
'vertical'
children*ReactNode
—
children*ReactNode
—- Name
- Type
React.ReactNode
Trigger
A button that opens the menu.
Renders a <button> element.
nativeButtonboolean
true
nativeButtonboolean
true
- Name
- Description
Whether the component renders a native
<button>element when replacing it via therenderprop. Set tofalseif the rendered element is not a button (e.g.<div>).- Type
boolean | undefined- Default
true
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
childrenReactNode
—
childrenReactNode
—- Name
- Type
React.ReactNode
classNamestring | function
—
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: Menu.Trigger.State) => string)
renderReactElement | function
—
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: Menu.Trigger.State, ) => ReactElement)
data-popup-open
Present when the corresponding menu is open.
data-pressed
Present when the trigger is pressed.
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
—
containerUnion
—- Name
- Description
A parent element to render the portal element into.
- Type
| HTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null | undefined
classNamestring | function
—
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: Menu.Portal.State) => string)
keepMountedboolean
false
keepMountedboolean
false
- Name
- Description
Whether to keep the portal mounted in the DOM while the popup is hidden.
- Type
boolean | undefined- Default
false
renderReactElement | function
—
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: Menu.Portal.State, ) => ReactElement)
Backdrop
An overlay displayed beneath the menu popup.
Renders a <div> element.
classNamestring | function
—
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: Menu.Backdrop.State) => string)
renderReactElement | function
—
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: Menu.Backdrop.State, ) => ReactElement)
data-open
Present when the menu is open.
data-closed
Present when the menu is closed.
data-starting-style
Present when the menu is animating in.
data-ending-style
Present when the menu is animating out.
Positioner
Positions the menu popup against the trigger.
Renders a <div> element.
collisionAvoidanceCollisionAvoidance
—
collisionAvoidanceCollisionAvoidance
—- Description
Determines how to handle collisions when positioning the popup.
- Type
| { side?: 'none' | 'flip' align?: 'none' | 'shift' | 'flip' fallbackAxisSide?: 'none' | 'start' | 'end' } | { side?: 'none' | 'shift' align?: 'none' | 'shift' fallbackAxisSide?: 'none' | 'start' | 'end' } | undefined- Example
<Positioner collisionAvoidance={{ side: 'shift', align: 'shift', fallbackAxisSide: 'none', }} />
alignAlign
'center'
alignAlign
'center'
- Name
- Description
How to align the popup relative to the specified side.
- Type
'center' | 'start' | 'end' | undefined- Default
'center'
alignOffsetnumber | OffsetFunction
0
alignOffsetnumber | OffsetFunction
0
- 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: Side align: Align 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'
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 | OffsetFunction
0
sideOffsetnumber | OffsetFunction
0
- 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: Side align: Align 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; }} />
arrowPaddingnumber
5
arrowPaddingnumber
5
- 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
—
anchorUnion
—- Name
- Description
An element to position the popup against. By default, the popup will be positioned against the trigger.
- Type
| Element | React.RefObject<Element | null> | VirtualElement | (() => Element | VirtualElement | null) | null | undefined
collisionBoundaryBoundary
'clipping-ancestors'
collisionBoundaryBoundary
'clipping-ancestors'
- Description
An element or a rectangle that delimits the area that the popup is confined to.
- Type
| Element | 'clipping-ancestors' | Element[] | Rect | undefined- Default
'clipping-ancestors'
collisionPaddingPadding
5
collisionPaddingPadding
5
- Name
- Description
Additional space to maintain from the edge of the collision boundary.
- Type
| { top?: number right?: number bottom?: number left?: number } | number | undefined- Default
5
stickyboolean
false
stickyboolean
false
- 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'fixed' | 'absolute'
'absolute'
positionMethod'fixed' | 'absolute'
'absolute'
- Name
- Description
Determines which CSS
positionproperty to use.- Type
'fixed' | 'absolute' | undefined- Default
'absolute'
trackAnchorboolean
true
trackAnchorboolean
true
- Name
- Description
Whether the popup tracks any layout shift of its positioning anchor.
- Type
boolean | undefined- Default
true
classNamestring | function
—
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: Menu.Positioner.State) => string)
renderReactElement | function
—
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: Menu.Positioner.State, ) => ReactElement)
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.
Popup
A container for the menu items.
Renders a <div> element.
finalFocusUnion
—
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: InteractionType, ) => boolean | void | HTMLElement | null) | undefined
idstring
—
idstring
—- Name
- Type
string | undefined
childrenReactNode
—
childrenReactNode
—- Name
- Type
React.ReactNode
classNamestring | function
—
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: Menu.Popup.State) => string)
renderReactElement | function
—
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: Menu.Popup.State, ) => ReactElement)
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.
Arrow
Displays an element positioned against the menu anchor.
Renders a <div> element.
classNamestring | function
—
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: Menu.Arrow.State) => string)
renderReactElement | function
—
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: Menu.Arrow.State, ) => ReactElement)
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-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.
Item
An individual interactive item in the menu.
Renders a <div> element.
labelstring
—
labelstring
—- Name
- Description
Overrides the text label to use when the item is matched during keyboard text navigation.
- Type
string | undefined
onClickfunction
—
onClickfunction
—- Name
- Description
The click handler for the menu item.
- Type
React.MouseEventHandler<HTMLElement> | undefined
closeOnClickboolean
true
closeOnClickboolean
true
- Name
- Description
Whether to close the menu when the item is clicked.
- Type
boolean | undefined- Default
true
nativeButtonboolean
false
nativeButtonboolean
false
- 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
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
idstring
—
idstring
—- Name
- Type
string | undefined
childrenReactNode
—
childrenReactNode
—- Name
- Type
React.ReactNode
classNamestring | function
—
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: Menu.Item.State) => string)
renderReactElement | function
—
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: Menu.Item.State, ) => ReactElement)
data-highlighted
Present when the menu item is highlighted.
data-disabled
Present when the menu item is disabled.
SubmenuRoot
Groups all parts of a submenu. Doesn’t render its own HTML element.
defaultOpenboolean
false
defaultOpenboolean
false
- Name
- Description
Whether the menu is initially open.
To render a controlled menu, use the
openprop instead.- Type
boolean | undefined- Default
false
openboolean
—
openboolean
—- Name
- Description
Whether the menu is currently open.
- Type
boolean | undefined
onOpenChangefunction
—
onOpenChangefunction
—- Name
- Description
Event handler called when the menu is opened or closed.
- Type
| (( open: boolean, eventDetails: Menu.SubmenuRoot.ChangeEventDetails, ) => void) | undefined
actionsRefRefObject<Menu.Root.Actions>
—
actionsRefRefObject<Menu.Root.Actions>
—- 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.
- Type
React.RefObject<Menu.Root.Actions> | undefined
closeParentOnEscboolean
true
closeParentOnEscboolean
true
- 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
true
onOpenChangeCompletefunction
—
onOpenChangeCompletefunction
—- Description
Event handler called after any animations complete when the menu is closed.
- Type
((open: boolean) => void) | undefined
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
openOnHoverboolean
true
openOnHoverboolean
true
- Name
- Description
Whether the submenu should open when the trigger is hovered.
- Type
boolean | undefined- Default
true
delaynumber
100
delaynumber
100
- 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
closeDelaynumber
0
closeDelaynumber
0
- 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
loopboolean
true
loopboolean
true
- 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
orientationMenu.Root.Orientation
'vertical'
orientationMenu.Root.Orientation
'vertical'
- Name
- Description
The visual orientation of the menu. Controls whether roving focus uses up/down or left/right arrow keys.
- Type
'horizontal' | 'vertical' | undefined- Default
'vertical'
children*ReactNode
—
children*ReactNode
—- Name
- Type
React.ReactNode
SubmenuTrigger
A menu item that opens a submenu.
Renders a <div> element.
labelstring
—
labelstring
—- Name
- Description
Overrides the text label to use when the item is matched during keyboard text navigation.
- Type
string | undefined
onClickfunction
—
onClickfunction
—- Name
- Type
React.MouseEventHandler<HTMLElement> | undefined
nativeButtonboolean
false
nativeButtonboolean
false
- 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
idstring
—
idstring
—- Name
- Type
string | undefined
childrenReactNode
—
childrenReactNode
—- Name
- Type
React.ReactNode
classNamestring | function
—
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: Menu.SubmenuTrigger.State) => string)
renderReactElement | function
—
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: Menu.SubmenuTrigger.State, ) => ReactElement)
data-popup-open
Present when the corresponding submenu is open.
Group
Groups related menu items with the corresponding label.
Renders a <div> element.
childrenReactNode
—
childrenReactNode
—- Name
- Description
The content of the component.
- Type
React.ReactNode
classNamestring | function
—
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: Menu.Group.State) => string)
renderReactElement | function
—
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: Menu.Group.State, ) => ReactElement)
GroupLabel
An accessible label that is automatically associated with its parent group.
Renders a <div> element.
classNamestring | function
—
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: Menu.GroupLabel.State) => string)
renderReactElement | function
—
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: Menu.GroupLabel.State, ) => ReactElement)
RadioGroup
Groups related radio items.
Renders a <div> element.
defaultValueany
—
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
valueany
—
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
onValueChangefunction
—
onValueChangefunction
—- Name
- Description
Function called when the selected value changes.
- Type
| (( value: any, eventDetails: Menu.RadioGroup.ChangeEventDetails, ) => void) | undefined
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
childrenReactNode
—
childrenReactNode
—- Name
- Description
The content of the component.
- Type
React.ReactNode
classNamestring | function
—
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: Menu.RadioGroup.State) => string)
renderReactElement | function
—
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: Menu.RadioGroup.State, ) => ReactElement)
RadioItem
A menu item that works like a radio button in a given group.
Renders a <div> element.
labelstring
—
labelstring
—- Name
- Description
Overrides the text label to use when the item is matched during keyboard text navigation.
- Type
string | undefined
value*any
—
value*any
—- Name
- Description
Value of the radio item. This is the value that will be set in the Menu.RadioGroup when the item is selected.
- Type
any
onClickfunction
—
onClickfunction
—- Name
- Description
The click handler for the menu item.
- Type
React.MouseEventHandler<HTMLElement> | undefined
closeOnClickboolean
false
closeOnClickboolean
false
- Name
- Description
Whether to close the menu when the item is clicked.
- Type
boolean | undefined- Default
false
nativeButtonboolean
false
nativeButtonboolean
false
- 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
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
idstring
—
idstring
—- Name
- Type
string | undefined
childrenReactNode
—
childrenReactNode
—- Name
- Type
React.ReactNode
classNamestring | function
—
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: Menu.RadioItem.State) => string)
renderReactElement | function
—
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: Menu.RadioItem.State, ) => ReactElement)
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.
RadioItemIndicator
Indicates whether the radio item is selected.
Renders a <div> element.
classNamestring | function
—
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: Menu.RadioItemIndicator.State) => string)
keepMountedboolean
false
keepMountedboolean
false
- Name
- Description
Whether to keep the HTML element in the DOM when the radio item is inactive.
- Type
boolean | undefined- Default
false
renderReactElement | function
—
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: Menu.RadioItemIndicator.State, ) => ReactElement)
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.
CheckboxItem
A menu item that toggles a setting on or off.
Renders a <div> element.
labelstring
—
labelstring
—- Name
- Description
Overrides the text label to use when the item is matched during keyboard text navigation.
- Type
string | undefined
defaultCheckedboolean
false
defaultCheckedboolean
false
- 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
—
checkedboolean
—- Name
- Description
Whether the checkbox item is currently ticked.
To render an uncontrolled checkbox item, use the
defaultCheckedprop instead.- Type
boolean | undefined
onCheckedChangefunction
—
onCheckedChangefunction
—- Name
- Description
Event handler called when the checkbox item is ticked or unticked.
- Type
| (( checked: boolean, eventDetails: Menu.CheckboxItem.ChangeEventDetails, ) => void) | undefined
onClickfunction
—
onClickfunction
—- Name
- Description
The click handler for the menu item.
- Type
React.MouseEventHandler<HTMLElement> | undefined
closeOnClickboolean
false
closeOnClickboolean
false
- Name
- Description
Whether to close the menu when the item is clicked.
- Type
boolean | undefined- Default
false
nativeButtonboolean
false
nativeButtonboolean
false
- 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
disabledboolean
false
disabledboolean
false
- Name
- Description
Whether the component should ignore user interaction.
- Type
boolean | undefined- Default
false
idstring
—
idstring
—- Name
- Type
string | undefined
classNamestring | function
—
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: Menu.CheckboxItem.State) => string)
renderReactElement | function
—
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: Menu.CheckboxItem.State, ) => ReactElement)
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.
CheckboxItemIndicator
Indicates whether the checkbox item is ticked.
Renders a <div> element.
classNamestring | function
—
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: Menu.CheckboxItemIndicator.State) => string)
keepMountedboolean
false
keepMountedboolean
false
- 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
—
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: Menu.CheckboxItemIndicator.State, ) => ReactElement)
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.
Separator
A separator element accessible to screen readers.
Renders a <div> element.
orientationOrientation
'horizontal'
orientationOrientation
'horizontal'
- Name
- Description
The orientation of the separator.
- Type
'horizontal' | 'vertical' | undefined- Default
'horizontal'
classNamestring | function
—
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: Separator.State) => string)
renderReactElement | function
—
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: Separator.State, ) => ReactElement)
Examples
Open on hover
To create a menu that opens on hover, add the openOnHover prop to the Root part. You can additionally configure how quickly the menu opens on hover using the delay prop.
Checkbox items
Use the <Menu.CheckboxItem> part to create a menu item that can toggle a setting on or off.
Radio items
Use the <Menu.RadioGroup> and <Menu.RadioItem> parts to create menu items that work like radio buttons.
Close on click
Use the closeOnClick prop to change whether the menu closes when an item is clicked.
// Close the menu when a checkbox item is clicked
<Menu.CheckboxItem closeOnClick />
// Keep the menu open when an item is clicked
<Menu.Item closeOnClick={false} />Group labels
Use the <Menu.GroupLabel> part to add a label to a <Menu.Group>
Nested menu
To create a submenu, nest another menu inside the parent menu with <Menu.SubmenuRoot>. Use the <Menu.SubmenuTrigger> part for the menu item that opens the nested menu.
<Menu.Root>
<Menu.Trigger />
<Menu.Portal>
<Menu.Positioner>
<Menu.Popup>
<Menu.Arrow />
<Menu.Item />
{/* Submenu */}
<Menu.SubmenuRoot>
<Menu.SubmenuTrigger />
<Menu.Portal>
<Menu.Positioner>
<Menu.Popup>
{/* Submenu items */}
</Menu.Popup>
</Menu.Positioner>
</Menu.Portal>
</Menu.SubmenuRoot>
</Menu.Popup>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>Navigate to another page
Use the render prop to compose a menu item with an anchor element.
<Menu.Item render={<a href="/projects">Go to Projects</a>} />Open a dialog
In order to open a dialog using a menu, control the dialog state and open it imperatively using the onClick handler on the menu item.
import * as React from 'react';
import { Dialog } from '@base-ui-components/react/dialog';
import { Menu } from '@base-ui-components/react/menu';
function ExampleMenu() {
const [dialogOpen, setDialogOpen] = React.useState(false);
return (
<React.Fragment>
<Menu.Root>
<Menu.Trigger>Open menu</Menu.Trigger>
<Menu.Portal>
<Menu.Positioner>
<Menu.Popup>
{/* Open the dialog when the menu item is clicked */}
<Menu.Item onClick={() => setDialogOpen(true)}>Open dialog</Menu.Item>
</Menu.Popup>
</Menu.Positioner>
</Menu.Portal>
</Menu.Root>
{/* Control the dialog state */}
<Dialog.Root open={dialogOpen} onOpenChange={setDialogOpen}>
<Dialog.Portal>
<Dialog.Backdrop />
<Dialog.Popup>
{/* Rest of the dialog */}
</Dialog.Popup>
</Dialog.Portal>
</Dialog.Root>
</React.Fragment>
);
}