Design system
Docs
Primitives

Dropdown menu

A Base UI menu on the menu tokens: items, radio groups, submenus, labels, shortcuts, separators

Import
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuRadioGroup,
  DropdownMenuRadioItem,
  DropdownMenuSeparator,
  DropdownMenuShortcut,
  DropdownMenuSub,
  DropdownMenuSubContent,
  DropdownMenuSubTrigger,
  DropdownMenuTrigger,
} from "@nyte-ai/ui";

Implemented in packages/ui/src/components/ui/dropdown-menu.tsx, wrapping @nyte-ai/ui/menu. DropdownMenu, DropdownMenuTrigger, DropdownMenuRadioGroup, and DropdownMenuSub are the Base UI parts (Root, Trigger, RadioGroup, SubmenuRoot) re-exported unstyled.

The desktop app has its own richer menu tier (checkbox items, switch items, command menu). See Desktop › Menu. This wrapper is for web hosts and demos.

Usage

  • Items are actions. For choosing one of several values, use a DropdownMenuRadioGroup; for a form-style select, use the headless Select.
  • variant="destructive" on the last item, after a separator.
  • inset on items and labels aligns their text with radio items in the same menu, which reserve --nyte-control-menu-inset on the left for the indicator.
  • DropdownMenuShortcut is display only. It does not bind the key.

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>

Example

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

Props

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.

StyledProps<Menu.Popup.Props> plus the positioning subset forwarded to Menu.Positioner:

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

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.

StyledProps<Menu.Item.Props> plus:

PropTypeDefaultDescription
insetbooleanfalseLeft padding to align with radio items.
variant"default" | "destructive""default"Destructive color; highlighted wash matches.

Sets data-slot="dropdown-menu-item", data-variant, and data-inset.

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.

DropdownMenuRadioItem is StyledProps<Menu.RadioItem.Props> plus inset. It renders the RadioItemIndicator with a check glyph in an IconBox.

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.

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.

StyledProps<Menu.SubmenuTrigger.Props> plus inset. Renders a trailing chevron.

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.

StyledProps<Menu.GroupLabel.Props> plus inset.

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.

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.

StyledProps<React.ComponentProps<"span">>. Pushed to the right with margin-left: auto, in --nyte-color-muted-foreground at --nyte-font-size-detail.

Accessibility

Base UI's menu model, unchanged:

  • Popup has role="menu"; items role="menuitem", radio items role="menuitemradio" with aria-checked, submenu triggers aria-haspopup="menu" and aria-expanded.
  • Arrow Down/Up move the highlight and wrap; Home/End jump; typing matches item text (override with label); Enter and Space activate; Escape closes and returns focus to the trigger.
  • Arrow Right opens a submenu and moves focus into it; Arrow Left closes it. Submenus also open on hover (openOnHover).
  • Disabled items are aria-disabled, skipped by keyboard navigation, and set data-disabled.
  • Separators are role="separator".

Styling

TokenRole
--nyte-layer-menuz-index (60), above dialogs
--nyte-menu-min-width, -max-width, -max-heightPopup box, bound to --available-*
--nyte-radius-menu, --nyte-elevation-menu, --nyte-color-popoverPopup surface
--nyte-font-size-label / --nyte-leading-labelItems
--nyte-color-muted-hover[data-highlighted] and [data-popup-open]
--nyte-color-destructive, -mutedDestructive item and its highlight
--nyte-control-menu-insetIndicator gutter / inset
--nyte-motion-normalFade + 0.98 scale on [data-starting-style] / [data-ending-style]