Components

Menu

A dropdown of actions with items, radio groups, and submenus

import { DropdownMenu, DropdownMenuContent, DropdownMenuItem } from "@nyte-ai/ui";
import { Menu } from "@nyte-ai/ui/menu";

A list of actions opened by a button, with keyboard navigation and submenus. The root export ships styled DropdownMenu* components. The @nyte-ai/ui/menu subpath gives you the same behavior unstyled when you need parts the styled set does not cover, such as checkbox items, links, or an arrow.

Usage

  • Items are actions. To choose one of several values use a DropdownMenuRadioGroup. For a form-style control use Select.
  • Put variant="destructive" on the last item, after a separator.
  • inset adds leading padding to an item or label, so its text lines up with rows that start with an icon.
  • DropdownMenuShortcut is display only. It does not bind the key.
  • closeOnClick controls whether clicking an item closes the menu. It defaults to true on Menu.Item and false on Menu.CheckboxItem.
  • Menu.LinkItem renders an <a>, so pass href instead of onClick.
  • openOnHover on Menu.Trigger opens the menu on hover after delay milliseconds. Submenu triggers open on hover already.
  • A trigger rendered outside Menu.Root connects to it through a handle from Menu.createHandle(), passed to the handle prop on both. Submenu triggers stay inside their Menu.SubmenuRoot.

Anatomy

<DropdownMenu>
  <DropdownMenuTrigger />
  <DropdownMenuContent>
    {/* Portal › Positioner › Popup */}
    <DropdownMenuLabel />
    <DropdownMenuItem>
      <DropdownMenuShortcut />
    </DropdownMenuItem>
    <DropdownMenuSeparator />
    <DropdownMenuRadioGroup>
      <DropdownMenuRadioItem /> {/* includes the indicator */}
    </DropdownMenuRadioGroup>
    <DropdownMenuSub>
      <DropdownMenuSubTrigger /> {/* includes the chevron */}
      <DropdownMenuSubContent /> {/* Content with side="right" */}
    </DropdownMenuSub>
  </DropdownMenuContent>
</DropdownMenu>
<Menu.Root>
  <Menu.Trigger />
  <Menu.Portal>
    <Menu.Backdrop />
    <Menu.Positioner>
      <Menu.Popup>
        <Menu.Arrow />
        <Menu.Item />
        <Menu.LinkItem />
        <Menu.Separator />

        <Menu.SubmenuRoot>
          <Menu.SubmenuTrigger />
          {/* Portal › Positioner › Popup, as above */}
        </Menu.SubmenuRoot>

        <Menu.Group>
          <Menu.GroupLabel />
        </Menu.Group>

        <Menu.RadioGroup>
          <Menu.RadioItem>
            <Menu.RadioItemIndicator />
          </Menu.RadioItem>
        </Menu.RadioGroup>

        <Menu.CheckboxItem>
          <Menu.CheckboxItemIndicator />
        </Menu.CheckboxItem>
      </Menu.Popup>
    </Menu.Positioner>
  </Menu.Portal>
</Menu.Root>

Examples

<DropdownMenu>
  <DropdownMenuTrigger render={<Button variant="outline" />}>Session</DropdownMenuTrigger>
  <DropdownMenuContent>
    <DropdownMenuItem>
      Rename
      <DropdownMenuShortcut>⌘R</DropdownMenuShortcut>
    </DropdownMenuItem>
    <DropdownMenuItem>Duplicate</DropdownMenuItem>
    <DropdownMenuSeparator />
    <DropdownMenuRadioGroup value={effort} onValueChange={setEffort}>
      <DropdownMenuLabel inset>Effort</DropdownMenuLabel>
      <DropdownMenuRadioItem value="low">Low</DropdownMenuRadioItem>
      <DropdownMenuRadioItem value="medium">Medium</DropdownMenuRadioItem>
      <DropdownMenuRadioItem value="high">High</DropdownMenuRadioItem>
    </DropdownMenuRadioGroup>
    <DropdownMenuSeparator />
    <DropdownMenuSub>
      <DropdownMenuSubTrigger>Move to</DropdownMenuSubTrigger>
      <DropdownMenuSubContent>
        <DropdownMenuItem>Inbox</DropdownMenuItem>
        <DropdownMenuItem>Archive</DropdownMenuItem>
      </DropdownMenuSubContent>
    </DropdownMenuSub>
    <DropdownMenuSeparator />
    <DropdownMenuItem variant="destructive">Delete</DropdownMenuItem>
  </DropdownMenuContent>
</DropdownMenu>

Open a dialog from an item by controlling the dialog and setting its state in onClick.

<DropdownMenuItem onClick={() => setRenameOpen(true)}>Rename</DropdownMenuItem>

Props

Each styled component wraps a Base UI part.

StyledPart
DropdownMenuMenu.Root
DropdownMenuTriggerMenu.Trigger
DropdownMenuContentMenu.Portal, Positioner, Popup
DropdownMenuItemMenu.Item
DropdownMenuLabelMenu.GroupLabel
DropdownMenuSeparatorMenu.Separator
DropdownMenuRadioGroupMenu.RadioGroup
DropdownMenuRadioItemMenu.RadioItem, RadioItemIndicator
DropdownMenuSubMenu.SubmenuRoot
DropdownMenuSubTriggerMenu.SubmenuTrigger
DropdownMenuSubContentDropdownMenuContent with submenu defaults
DropdownMenuShortcuta <span> pushed to the right of the item

DropdownMenuContent forwards these to the positioner and passes the rest to the popup.

PropTypeDefaultDescription
sideMenu.Positioner.Props["side"]"bottom"Which side of the trigger.
alignMenu.Positioner.Props["align"]"start"Alignment along that side.
sideOffsetnumber4Gap from the trigger.
alignOffsetMenu.Positioner.Props["alignOffset"]0Shift along the alignment axis.

DropdownMenuSubContent takes the same props with defaults side="right", align="start", sideOffset={0}, alignOffset={-3}.

DropdownMenuItem, DropdownMenuRadioItem, DropdownMenuSubTrigger, and DropdownMenuLabel add inset. DropdownMenuItem also adds variant.

PropTypeDefaultDescription
insetbooleanfalseLeading padding for rows that start with an icon.
variant"default" | "destructive""default"Destructive color.

Every styled export accepts xstyle alongside className and style. See Theming.

The part tables below come from Base UI, MIT, © Material-UI SAS.

Root

Groups all parts of the menu. Doesn't render its own HTML element.

Root Props:

PropTypeDefaultDescription
defaultOpenbooleanfalseWhether the menu is initially open. To render a controlled menu, use the open prop instead.
openboolean-Whether the menu is currently open.
onOpenChange((open: boolean, eventDetails: Menu.Root.ChangeEventDetails) => void)-Event handler called when the menu is opened or closed.
highlightItemOnHoverbooleantrueWhether moving the pointer over items should highlight them. Disabling this prop allows CSS :hover to be differentiated from the :focus (data-highlighted) state.
actionsRefReact.RefObject<Menu.Root.Actions | null>-A ref to imperative actions. unmount: Manually unmounts the menu. Call this after any externally controlled closing animation finishes.close: When specified, the menu can be closed imperatively.
closeParentOnEscbooleanfalseWhen in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu.
defaultTriggerIdstring | null-ID of the trigger that the menu is associated with. This is useful in conjunction with the defaultOpen prop to create an initially open menu.
handleMenu.Handle<Payload>-A handle to associate the menu with a trigger. If specified, allows external triggers to control the menu's open state.
loopFocusbooleantrueWhether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.
modalbooleantrueDetermines if the menu enters a modal state when open. true: user interaction is limited to the menu: document page scroll is locked and pointer interactions on outside elements are disabled.false: user interaction with the rest of the document is allowed. On touch devices, a true modal blocks outside taps but leaves the page scrollable unless the popup spans nearly the full viewport width, matching native iOS behavior. Nested menus ignore this prop, and menus opened by hover are never modal.
onOpenChangeComplete((open: boolean) => void)-Event handler called after any animations complete when the menu is opened or closed.
triggerIdstring | null-ID of the trigger that the menu is associated with. This is useful in conjunction with the open prop to create a controlled menu. There's no need to specify this prop when the menu is uncontrolled (that is, when the open prop is not set).
disabledbooleanfalseWhether the component should ignore user interaction.
orientationMenu.Root.Orientation'vertical'The visual orientation of the menu. Controls whether roving focus uses up/down or left/right arrow keys.
childrenReact.ReactNode | PayloadChildRenderFunction<Payload>-The content of the menu. This can be a regular React node or a render function that receives the payload of the active trigger.

Trigger

A button that opens the menu. Renders a <button> element.

Trigger Props:

PropTypeDefaultDescription
handleMenu.Handle<Payload>-A handle to associate the trigger with a menu.
nativeButtonbooleantrueWhether the component renders a native <button> element when replacing it via the render prop. Set to false if the rendered element is not a button (for example, <div>).
payloadPayload-A payload to pass to the menu when it is opened.
disabledbooleanfalseWhether the component should ignore user interaction.
openOnHoverboolean-Whether the menu should also open when the trigger is hovered.
delaynumber100How long to wait before the menu may be opened on hover. Specified in milliseconds. Requires the openOnHover prop.
closeDelaynumber0How long to wait before closing the menu that was opened on hover. Specified in milliseconds. Requires the openOnHover prop.
childrenReact.ReactNode--
classNamestring | ((state: Menu.Trigger.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.Trigger.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Menu.Trigger.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Trigger Data Attributes:

AttributeTypeDescription
data-popup-open-Present when the corresponding menu is open.
data-pressed-Present when the trigger is pressed.
data-disabled-Present when the trigger is disabled.

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.

Portal Props:

PropTypeDefaultDescription
containerHTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | null-A parent element to render the portal element into.
classNamestring | ((state: Menu.Portal.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.Portal.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
keepMountedbooleanfalseWhether to keep the portal mounted in the DOM while the popup is hidden.
renderReactElement | ((props: HTMLProps, state: Menu.Portal.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Backdrop

An overlay displayed beneath the menu popup. Renders a <div> element.

Backdrop Props:

PropTypeDefaultDescription
classNamestring | ((state: Menu.Backdrop.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.Backdrop.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Menu.Backdrop.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Backdrop Data Attributes:

AttributeTypeDescription
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.

Positioner

Positions the menu popup against the trigger. Renders a <div> element.

Positioner Props:

PropTypeDefaultDescription
disableAnchorTrackingbooleanfalseWhether to disable the popup from tracking any layout shift of its positioning anchor.
alignAlign'center'How to align the popup relative to the specified side. Submenus and menubars default to 'start'.
alignOffsetnumber | OffsetFunction0Additional 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 data object parameter with the following properties: data.anchor: the dimensions of the anchor element with properties width and height.data.positioner: the dimensions of the positioner element with properties width and height.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.
sideSide'bottom'Which side of the anchor element to align the popup against. May automatically change to avoid collisions. Submenus and vertical menubars default to 'inline-end'.
sideOffsetnumber | OffsetFunction0Distance 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 data object parameter with the following properties: data.anchor: the dimensions of the anchor element with properties width and height.data.positioner: the dimensions of the positioner element with properties width and height.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.
arrowPaddingnumber5Minimum 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.
anchorElement | VirtualElement | React.RefObject<Element | null> | (() => Element | VirtualElement | null) | null-An element to position the popup against. By default, the popup will be positioned against the trigger.
collisionAvoidanceCollisionAvoidance-Determines how to handle collisions when positioning the popup. side controls overflow on the preferred placement axis (top/bottom or left/right): 'flip': keep the requested side when it fits; otherwise try the opposite side (top and bottom, or left and right).'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. align controls overflow on the alignment axis (start/center/end): 'flip': keep side, but swap start and end when 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. fallbackAxisSide controls fallback behavior on the perpendicular axis when the preferred axis cannot fit: 'start': allow perpendicular fallback and try the logical start side first (top before bottom, or left before right in LTR).'end': allow perpendicular fallback and try the logical end side first (bottom before top, or right before left in LTR).'none': do not fallback to the perpendicular axis. When side is 'shift', explicitly setting align only supports 'shift' or 'none'. If align is omitted, it defaults to 'flip'.
collisionBoundaryBoundary'clipping-ancestors'An element or a rectangle that delimits the area that the popup is confined to.
collisionPaddingPadding5Additional space to maintain from the edge of the collision boundary.
stickybooleanfalseWhether to maintain the popup in the viewport after the anchor element was scrolled out of view.
positionMethod'absolute' | 'fixed''absolute'Determines which CSS position property to use.
classNamestring | ((state: Menu.Positioner.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.Positioner.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Menu.Positioner.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

alignOffset Prop Example:

<Positioner
  alignOffset={({ side, align, anchor, positioner }) => {
    return side === 'top' || side === 'bottom' ? anchor.width : anchor.height;
  }}
/>

sideOffset Prop Example:

<Positioner
  sideOffset={({ side, align, anchor, positioner }) => {
    return side === 'top' || side === 'bottom' ? anchor.height : anchor.width;
  }}
/>

collisionAvoidance Prop Example:

<Positioner
  collisionAvoidance={{
    side: 'shift',
    align: 'shift',
    fallbackAxisSide: 'none',
  }}
/>

Positioner Data Attributes:

AttributeTypeDescription
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'start' | 'center' | 'end'Indicates how the popup is aligned relative to the specified side.
data-side'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'Indicates which side the popup is positioned relative to the anchor.

Positioner CSS Variables:

VariableTypeDescription
--anchor-heightnumberThe anchor's height.
--anchor-widthnumberThe anchor's width.
--available-heightnumberThe available height between the anchor and the edge of the viewport.
--available-widthnumberThe available width between the anchor and the edge of the viewport.
--positioner-heightnumberThe height of the menu's positioner. It is important to set height to this value when using CSS to animate size changes.
--positioner-widthnumberThe width of the menu's positioner. It is important to set width to this value when using CSS to animate size changes.
--transform-originstringThe coordinates that this element is anchored to. Used for animations and transitions.

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

Popup Props:

PropTypeDefaultDescription
finalFocusboolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | void | HTMLElement | null)-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, or keyboard). Return an element to focus, true to use the default behavior, or false/undefined to do nothing.
childrenReact.ReactNode--
classNamestring | ((state: Menu.Popup.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.Popup.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Menu.Popup.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Popup Data Attributes:

AttributeTypeDescription
data-open-Present when the menu is open.
data-closed-Present when the menu is closed.
data-align'start' | 'center' | 'end'Indicates how the popup is aligned relative to specified side.
data-instant'click' | 'dismiss' | 'group' | 'trigger-change'Present if animations should be instant.
data-side'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'Indicates which side the popup is positioned relative to the anchor.
data-starting-style-Present when the menu begins 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.

Arrow Props:

PropTypeDefaultDescription
classNamestring | ((state: Menu.Arrow.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.Arrow.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Menu.Arrow.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Arrow Data Attributes:

AttributeTypeDescription
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'start' | 'center' | 'end'Indicates how the popup is aligned relative to specified side.
data-side'top' | 'bottom' | 'left' | 'right' | 'inline-end' | 'inline-start'Indicates which side the popup is positioned relative to the anchor.

Viewport

A viewport for displaying content transitions. This component is only required if one popup can be opened by multiple triggers, its content changes based on the trigger, and switching between them is animated. Renders a <div> element.

Viewport Props:

PropTypeDefaultDescription
childrenReact.ReactNode-The content to render inside the transition container.
classNamestring | ((state: Menu.Viewport.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.Viewport.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Menu.Viewport.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Viewport Data Attributes:

AttributeTypeDescription
data-activation-direction`${'left' | 'right' | ''} ${'down' | 'up' | ''}`Indicates the direction from which the popup was activated. This can be used to create directional animations based on how the popup was triggered. Contains space-separated values for both horizontal and vertical axes.
data-current-Applied to the direct child of the viewport when no transitions are present or the new content when it's entering.
data-instant'click' | 'dismiss' | 'group' | 'trigger-change'Present if animations should be instant.
data-previous-Applied to the direct child of the viewport that contains the exiting content when transitions are present.
data-transitioning-Indicates that the viewport is currently transitioning between old and new content.

Viewport CSS Variables:

VariableTypeDescription
--popup-height``The height of the parent popup. This variable is placed on the 'previous' container and stores the height of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.
--popup-width``The width of the parent popup. This variable is placed on the 'previous' container and stores the width of the popup when the previous content was rendered. It can be used to freeze the dimensions of the popup when animating between different content.

Item

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

Item Props:

PropTypeDefaultDescription
labelstring-Overrides the text label to use when the item is matched during keyboard text navigation.
onClick((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void)-The click handler for the menu item.
closeOnClickbooleantrueWhether to close the menu when the item is clicked.
nativeButtonbooleanfalseWhether the component renders a native <button> element when replacing it via the render prop. Set to true if the rendered element is a native button.
disabledbooleanfalseWhether the component should ignore user interaction.
classNamestring | ((state: Menu.Item.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.Item.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Menu.Item.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Item Data Attributes:

AttributeTypeDescription
data-highlighted-Present when the menu item is highlighted.
data-disabled-Present when the menu item is disabled.

LinkItem

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

LinkItem Props:

PropTypeDefaultDescription
labelstring-Overrides the text label to use when the item is matched during keyboard text navigation.
closeOnClickbooleanfalseWhether to close the menu when the item is clicked.
classNamestring | ((state: Menu.LinkItem.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.LinkItem.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, state: Menu.LinkItem.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

LinkItem Data Attributes:

AttributeTypeDescription
data-highlighted-Present when the link is highlighted.

Separator

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

Separator Props:

PropTypeDefaultDescription
orientationOrientation'horizontal'The orientation of the separator.
classNamestring | ((state: SeparatorState) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: SeparatorState) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: SeparatorState) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

Group

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

Group Props:

PropTypeDefaultDescription
childrenReact.ReactNode-The content of the component.
classNamestring | ((state: Menu.Group.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.Group.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Menu.Group.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

GroupLabel

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

GroupLabel Props:

PropTypeDefaultDescription
classNamestring | ((state: Menu.GroupLabel.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.GroupLabel.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Menu.GroupLabel.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

RadioGroup

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

RadioGroup Props:

PropTypeDefaultDescription
defaultValueany-The uncontrolled value of the radio item that should be initially selected. To render a controlled radio group, use the value prop instead.
valueany-The controlled value of the radio item that should be currently selected. To render an uncontrolled radio group, use the defaultValue prop instead.
onValueChange((value: any, eventDetails: Menu.RadioGroup.ChangeEventDetails) => void)-Function called when the selected value changes.
disabledbooleanfalseWhether the component should ignore user interaction.
childrenReact.ReactNode-The content of the component.
classNamestring | ((state: Menu.RadioGroup.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.RadioGroup.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Menu.RadioGroup.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

RadioItem

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

RadioItem Props:

PropTypeDefaultDescription
labelstring-Overrides the text label to use when the item is matched during keyboard text navigation.
value*any-Value of the radio item. This is the value that will be set in the Menu.RadioGroup when the item is selected.
onClick((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void)-The click handler for the menu item.
closeOnClickbooleanfalseWhether to close the menu when the item is clicked.
nativeButtonbooleanfalseWhether the component renders a native <button> element when replacing it via the render prop. Set to true if the rendered element is a native button.
disabledbooleanfalseWhether the component should ignore user interaction.
classNamestring | ((state: Menu.RadioItem.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.RadioItem.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Menu.RadioItem.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

RadioItem Data Attributes:

AttributeTypeDescription
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 <span> element.

RadioItemIndicator Props:

PropTypeDefaultDescription
classNamestring | ((state: Menu.RadioItemIndicator.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.RadioItemIndicator.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
keepMountedbooleanfalseWhether to keep the HTML element in the DOM when the radio item is inactive.
renderReactElement | ((props: HTMLProps, state: Menu.RadioItemIndicator.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

RadioItemIndicator Data Attributes:

AttributeTypeDescription
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.

CheckboxItem

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

CheckboxItem Props:

PropTypeDefaultDescription
labelstring-Overrides the text label to use when the item is matched during keyboard text navigation.
defaultCheckedbooleanfalseWhether the checkbox item is initially ticked. To render a controlled checkbox item, use the checked prop instead.
checkedboolean-Whether the checkbox item is currently ticked. To render an uncontrolled checkbox item, use the defaultChecked prop instead.
onCheckedChange((checked: boolean, eventDetails: Menu.CheckboxItem.ChangeEventDetails) => void)-Event handler called when the checkbox item is ticked or unticked.
onClick((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void)-The click handler for the menu item.
closeOnClickbooleanfalseWhether to close the menu when the item is clicked.
nativeButtonbooleanfalseWhether the component renders a native <button> element when replacing it via the render prop. Set to true if the rendered element is a native button.
disabledbooleanfalseWhether the component should ignore user interaction.
classNamestring | ((state: Menu.CheckboxItem.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.CheckboxItem.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Menu.CheckboxItem.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

CheckboxItem Data Attributes:

AttributeTypeDescription
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 <span> element.

CheckboxItemIndicator Props:

PropTypeDefaultDescription
classNamestring | ((state: Menu.CheckboxItemIndicator.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.CheckboxItemIndicator.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
keepMountedbooleanfalseWhether to keep the HTML element in the DOM when the checkbox item is not checked.
renderReactElement | ((props: HTMLProps, state: Menu.CheckboxItemIndicator.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

CheckboxItemIndicator Data Attributes:

AttributeTypeDescription
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.

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

SubmenuRoot Props:

PropTypeDefaultDescription
defaultOpenbooleanfalseWhether the menu is initially open. To render a controlled menu, use the open prop instead.
openboolean-Whether the menu is currently open.
onOpenChange((open: boolean, eventDetails: Menu.SubmenuRoot.ChangeEventDetails) => void)-Event handler called when the menu is opened or closed.
highlightItemOnHoverbooleantrueWhether moving the pointer over items should highlight them. Disabling this prop allows CSS :hover to be differentiated from the :focus (data-highlighted) state.
actionsRefReact.RefObject<Menu.Root.Actions | null>-A ref to imperative actions. unmount: Manually unmounts the menu. Call this after any externally controlled closing animation finishes.close: When specified, the menu can be closed imperatively.
closeParentOnEscbooleanfalseWhen in a submenu, determines whether pressing the Escape key closes the entire menu, or only the current child menu.
loopFocusbooleantrueWhether to loop keyboard focus back to the first item when the end of the list is reached while using the arrow keys.
onOpenChangeComplete((open: boolean) => void)-Event handler called after any animations complete when the menu is opened or closed.
disabledbooleanfalseWhether the component should ignore user interaction.
orientationMenu.Root.Orientation'vertical'The visual orientation of the menu. Controls whether roving focus uses up/down or left/right arrow keys.
childrenReact.ReactNode-The content of the submenu.

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

SubmenuTrigger Props:

PropTypeDefaultDescription
labelstring-Overrides the text label to use when the item is matched during keyboard text navigation.
onClick((event: BaseUIEvent<React.MouseEvent<HTMLDivElement, MouseEvent>>) => void)--
nativeButtonbooleanfalseWhether the component renders a native <button> element when replacing it via the render prop. Set to true if the rendered element is a native button.
disabledbooleanfalseWhether the component should ignore user interaction.
openOnHoverbooleantrueWhether the menu should also open when the trigger is hovered.
delaynumber100How long to wait before the menu may be opened on hover. Specified in milliseconds. Requires the openOnHover prop.
closeDelaynumber0How long to wait before closing the menu that was opened on hover. Specified in milliseconds. Requires the openOnHover prop.
classNamestring | ((state: Menu.SubmenuTrigger.State) => string | undefined)-CSS class applied to the element, or a function that returns a class based on the component's state.
styleReact.CSSProperties | ((state: Menu.SubmenuTrigger.State) => React.CSSProperties | undefined)-Style applied to the element, or a function that returns a style object based on the component's state.
renderReactElement | ((props: HTMLProps, state: Menu.SubmenuTrigger.State) => ReactElement)-Allows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a ReactElement or a function that returns the element to render.

SubmenuTrigger Data Attributes:

AttributeTypeDescription
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.

Accessibility

  • The popup has role="menu", items role="menuitem", radio items role="menuitemradio" with aria-checked, submenu triggers aria-haspopup="menu" and aria-expanded.
  • Arrow Down and Up move the highlight and wrap, Home and End jump, typing matches item text (override with label), Enter and Space activate, Escape closes and returns focus to the trigger.
  • orientation on the root switches arrow navigation to left and right. loopFocus={false} stops the highlight wrapping at the ends.
  • Arrow Right opens a submenu and moves focus into it, Arrow Left closes it. Submenus also open on hover.
  • Disabled items are aria-disabled. They stay reachable with the arrow keys and do not activate.
  • Separators are role="separator".