Skip to content

Molecules · Dropdown menu

Dropdown menu

A short list of actions behind a button. It uses the same background as Select, so the system's two pop-ups look like one family. The highlighted item gets a fill, as it does everywhere else.

Best for
A short list of actions, under about eight, behind a button.
Not for
Picking a value for a form: use Select.

This page as Markdown, a plain-text copy for a coding agent (an AI tool that writes code).

Examples

Actions

No action yet.

Code
tsx
function ActionsExample() {  const [lastAction, setLastAction] = useState('No action yet.')  const [pinned, setPinned] = useState(false)​  return (    <div className="flex flex-col items-start gap-3">      <DropdownMenu>        <DropdownMenuTrigger asChild>          <Button variant="secondary">Manifest actions</Button>        </DropdownMenuTrigger>        <DropdownMenuContent>          <DropdownMenuLabel>Manifest</DropdownMenuLabel>          <DropdownMenuItem shortcut="D" onSelect={() => setLastAction('Duplicated.')}>            Duplicate          </DropdownMenuItem>          <DropdownMenuCheckboxItem            checked={pinned}            onCheckedChange={checked => {              setPinned(checked)              setLastAction(checked ? 'Pinned to top.' : 'Unpinned.')            }}          >            Pin to top          </DropdownMenuCheckboxItem>          <DropdownMenuSeparator />          <DropdownMenuItem tone="hostile" onSelect={() => setLastAction('Archived.')}>            Archive          </DropdownMenuItem>        </DropdownMenuContent>      </DropdownMenu>      <p className={docsProse}>{lastAction}</p>    </div>  )}​<ActionsExample />

With icons and shortcuts

Code
tsx
function IconsAndShortcutsExample() {  return (    <DropdownMenu>      <DropdownMenuTrigger asChild>        <Button variant="secondary">Depot manifest</Button>      </DropdownMenuTrigger>      <DropdownMenuContent>        <DropdownMenuItem icon={<Copy />} shortcut="⌘C">          Copy        </DropdownMenuItem>        <DropdownMenuItem icon={<CopyPlus />} shortcut="⌘D">          Duplicate        </DropdownMenuItem>        <DropdownMenuItem icon={<Download />} shortcut="⌘E">          Export        </DropdownMenuItem>      </DropdownMenuContent>    </DropdownMenu>  )}​<IconsAndShortcutsExample />

Radio items and a submenu

Sorted by newest. Not moved.

Code
tsx
function RadioAndSubmenuExample() {  const [sort, setSort] = useState('newest')  const [moved, setMoved] = useState('Not moved.')​  return (    <div className="flex flex-col items-start gap-3">      <DropdownMenu>        <DropdownMenuTrigger asChild>          <Button variant="secondary">Replica options</Button>        </DropdownMenuTrigger>        <DropdownMenuContent>          <DropdownMenuLabel>Sort by</DropdownMenuLabel>          <DropdownMenuRadioGroup value={sort} onValueChange={setSort}>            <DropdownMenuRadioItem value="newest">Newest</DropdownMenuRadioItem>            <DropdownMenuRadioItem value="price">Price</DropdownMenuRadioItem>            <DropdownMenuRadioItem value="weight">Weight</DropdownMenuRadioItem>          </DropdownMenuRadioGroup>          <DropdownMenuSeparator />          <DropdownMenuSub>            <DropdownMenuSubTrigger icon={<FolderInput />}>Move to</DropdownMenuSubTrigger>            <DropdownMenuSubContent>              <DropdownMenuItem onSelect={() => setMoved('Moved to the armoury.')}>Armoury</DropdownMenuItem>              <DropdownMenuItem onSelect={() => setMoved('Moved to the workshop.')}>Workshop</DropdownMenuItem>              <DropdownMenuItem onSelect={() => setMoved('Moved to the depot.')}>Depot</DropdownMenuItem>            </DropdownMenuSubContent>          </DropdownMenuSub>        </DropdownMenuContent>      </DropdownMenu>      <p className={docsProse}>        Sorted by {sort}. {moved}      </p>    </div>  )}​<RadioAndSubmenuExample />

From an icon button

Code
tsx
function IconButtonTriggerExample() {  return (    <DropdownMenu>      <DropdownMenuTrigger asChild>        <IconButton label="Depot actions" variant="secondary">          <MoreHorizontal aria-hidden="true" />        </IconButton>      </DropdownMenuTrigger>      <DropdownMenuContent align="end">        <DropdownMenuItem>View manifest</DropdownMenuItem>        <DropdownMenuItem>Reassign</DropdownMenuItem>        <DropdownMenuSeparator />        <DropdownMenuItem tone="hostile">Decommission</DropdownMenuItem>      </DropdownMenuContent>    </DropdownMenu>  )}​<IconButtonTriggerExample />

Anatomy

PartWhat it is
TriggerA Button or IconButton, passed in through asChild. Radix (the library underneath) adds aria-haspopup and aria-expanded. These are ARIA (Accessible Rich Internet Applications) attributes that tell screen readers the button opens a menu and whether it's open.
ContentRendered in a portal, at the end of the page, so nothing clips it. Sunken surface, a strong thin border, crosshair corners. M7: it slides down out of the trigger to open and back up into it to close (the other way round when it opens above).
Item36px (pixels) tall. When highlighted: the signal fill with ink-coloured text.
Hostile itemFor a destructive action. Hostile-coloured text at rest, and the hostile fill with ink text when highlighted.
Checkbox itemShows a tick when on. Screen readers get it as a menuitemcheckbox with aria-checked.
LabelUses text.secondary, so it reads as a heading over the items. It doesn't use text.label: on this background (surface.sunken) that token fails SC 1.4.3, the contrast rule in WCAG (the Web Content Accessibility Guidelines).
SeparatorA thin line.
Radio itemOne choice in a RadioGroup. Screen readers get it as a menuitemradio with aria-checked. Its mark is a small filled square, never a dot.
Sub triggerAn item with a chevron that opens a submenu. While the highlight is inside the submenu, the sub trigger keeps a 1px strong line just inside its edge.
Sub contentThe submenu: the same surface and M7 slide as Content, aligned so its first row sits level with its trigger.
ShortcutText on the right that screen readers skip (aria-hidden), plus aria-keyshortcuts on the item so they announce it once. It only displays the key: the page has to make the key work.

Props

open (Root)boolean
Whether the menu is open, when the page keeps track of it (controlled).
defaultOpen (Root)boolean
Whether it starts open, when the menu keeps track itself (uncontrolled).
onOpenChange (Root)(open: boolean) => void
Called when the menu opens or closes.
modal (Root)booleanDefault true
While open, keyboard focus stays inside the menu and the page behind can't scroll.
align (Content)'start' | 'center' | 'end'Default 'center'
Alignment against the trigger.
side (Content)'top' | 'right' | 'bottom' | 'left'
Preferred side of the trigger.
sideOffset (Content)numberDefault 4
Gap between trigger and content, in pixels.
onSelect (Item)(event: Event) => void
Called when the item is chosen.
disabled (Item)booleanDefault false
The item can't be chosen, and typing letters (typeahead) skips it.
tone (Item)'default' | 'hostile'Default 'default'
Use hostile for a destructive action: hostile-coloured text at rest, the hostile fill with ink text when highlighted.
asChild (Item)booleanDefault false
Makes the one child (a link) the item, for a menu of links. icon and shortcut are ignored then; put the content inside the link.
icon (Item)ReactNode
A small icon before the text, hidden from screen readers (aria-hidden).
shortcut (Item)string
Shown on the right and passed to screen readers as aria-keyshortcuts. It only displays the key: the menu never makes the key work.
checked (Checkbox item)boolean
Whether the tick shows.
onCheckedChange (Checkbox item)(checked: boolean) => void
Called when the checkbox item is toggled.
value (RadioGroup)string
The checked radio item.
onValueChange (RadioGroup)(value: string) => void
Called with the chosen radio item value.
value (RadioItem)string
This radio item's own value.
icon (SubTrigger)ReactNode
A small icon before the text, hidden from screen readers, as on Item.
open / defaultOpen / onOpenChange (Sub)boolean / boolean / (open: boolean) => void
Whether the submenu is open, tracked by the page (controlled) or by the submenu (uncontrolled). You'll usually leave these alone.
alignOffset (SubContent)numberDefault -5
Shifts the submenu so its first row lines up with its trigger.
classNamestring
Extra CSS classes, merged with the part's own. When two Tailwind classes clash, the later one wins. Every part takes it.
refRef<HTMLDivElement>
Passed through to the rendered element (the DOM node). On Content, Item, Checkbox item, Radio item, Sub trigger and Sub content.

Keyboard

KeysResult
EnterSpaceArrowDownOn the trigger: opens, highlighting the first item.
ArrowUpArrowDownMoves the highlight.
HomeEndJumps to the first or last item.
EnterSpaceRuns the highlighted item.
EscapeCloses the menu and puts focus back on the trigger.
ArrowRightOn a sub trigger: opens the submenu, highlighting its first item.
ArrowLeftIn a submenu: closes it, and you're back on its trigger.
A–ZTypeahead: jumps to the next item that starts with the letters you type.

Do and don't

Do

  • Keep menus under about eight items.
  • Put the destructive item last, after a separator, with the hostile tone.
  • Name an icon-only trigger for what the menu holds: 'Manifest actions', not 'More'.
  • Use a radio group for a setting the menu shows the current value of: sort order, density.
  • Name a sub trigger for what it holds: 'Move to', 'Export as'.

Don't

  • Don't use a menu to pick a value for a form. That's what Select is for.
  • Don't put a submenu inside a submenu. One level at most.
  • Don't use radio items to run actions. A radio item sets a value, and the menu keeps showing it.
  • Don't make every item hostile to add weight. Hostile means it destroys something.