Demos

An account menu with icons, shortcuts, and a destructive item.

Usage

Use a dropdown menu to group actions that do not need to be on screen all the time, such as account options or the actions on a report. To pick a value for a form field, use a Select.

Import it from @workspace/ui/components/dropdown-menu.

Anatomy

  • DropdownMenu — Holds the open state.
  • DropdownMenuTrigger — Opens the menu. Pass a button through render.
  • DropdownMenuContent — The floating panel.
  • DropdownMenuItem — An action. Runs onClick and closes the menu.
  • DropdownMenuGroup and DropdownMenuLabel — A labelled set of items. A label must sit inside a group.
  • DropdownMenuSeparator — A line between sets of items.
  • DropdownMenuShortcut — A keyboard hint at the end of an item. It is only a hint; bind the key yourself.
  • DropdownMenuCheckboxItem — An item that toggles on and off.
  • DropdownMenuRadioGroup and DropdownMenuRadioItem — Items where one is chosen.
  • DropdownMenuSub, DropdownMenuSubTrigger, and DropdownMenuSubContent — A nested menu.

Notes

  • Arrow keys move between items, and typing a letter jumps to the matching item.
  • Put destructive items last, after a separator.
  • Keep menus short. Nest at most one level deep.

Examples

Checkboxes

Items that toggle filters on and off. The menu stays open while you click them.

Radio group

Choose one option. The trigger shows the current choice.

A nested menu that opens to the side. Add a chevron to the trigger yourself.

Props

These are the props you set most often. Unlisted props pass through to the underlying element.

PropTypeDefaultDescription
openboolean—Open state when controlled.
onOpenChange(open) => void—Called when the menu opens or closes.
PropTypeDefaultDescription
side"top", "bottom", "left", "right", "inline-start", or "inline-end"bottomSide of the trigger to open on.
align"start", "center", or "end"startAlignment along that side.
sideOffsetnumber4Gap from the trigger, in pixels.
alignOffsetnumber0Shift along the side, in pixels.
PropTypeDefaultDescription
variant"default" or "destructive"defaultdestructive colours the item red.
insetbooleanfalseIndents the item to line up with items that have icons.
disabledbooleanfalseBlocks the item.
onClick(event) => void—Runs the action.
PropTypeDefaultDescription
checkedboolean—State when controlled.
onCheckedChange(checked) => void—Called when the item toggles.
PropTypeDefaultDescription
valuestring—The chosen item when controlled.
onValueChange(value) => void—Called when the choice changes.