ui-kit0.0

Overlays

Dropdown menu

A focused list of actions on a trigger.

Usage

Compose DropdownMenu, a trigger and the content. Items take an icon and a shortcut; variant="destructive" colours a risky action. Submenus open to the side on hover or ArrowRight.

When to use

  • A short list of actions that belong to one control: an account, a row, a toolbar overflow.
  • Toggles and single-choice options that apply straight away.

Not for: choosing a value for a form field (use a select), navigation between pages (use links or tabs), or rich content (use a popover).

Row actions

An icon-only trigger needs an aria-label. Align the menu to the trigger’s edge with placement="bottom-end"; disabled items are skipped by the arrow keys.

Q3 roadmap.pdf2.4 MB · edited 3 days ago

Checkbox items that keep it open

Choosing an item closes the menu. For settings people adjust several at once, call event.preventDefault() in onSelect.

API

DropdownMenu

PropTypeDefaultDescription
openboolean—Controlled open state.
defaultOpenbooleanfalseInitial state when uncontrolled.
onOpenChange(open: boolean) => void—Called when the menu asks to open or close.

DropdownMenuContent

PropTypeDefaultDescription
placement'top' | 'right' | 'bottom' | 'left' (+ '-start' | '-end')'bottom-start'Preferred side and alignment.
align'start' | 'center' | 'end'—Overrides the alignment of placement.
offsetnumber6Gap to the trigger, px.
matchWidthbooleanfalseAt least as wide as the trigger.

DropdownMenuItem

PropTypeDefaultDescription
iconReactNode—Leading 16px icon.
shortcutReactNode—Shortcut hint on the right.
variant'default' | 'destructive''default'Destructive colours the item red.
disabledboolean—Skipped by the arrow keys, cannot be chosen.
insetboolean—Indent to line up with checkbox and radio items.
onSelect(event: Event) => void—Called when chosen. event.preventDefault() keeps the menu open.
asChildboolean—Render your own element, e.g. a link.

Checkbox and radio items

PropTypeDefaultDescription
DropdownMenuCheckboxItem checkedboolean—Controlled state; also defaultChecked and onCheckedChange.
DropdownMenuRadioGroup valuestring—Controlled value; also defaultValue and onValueChange.
DropdownMenuRadioItem valuestring—The value this item selects.

Also: DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuGroup, DropdownMenuSub, DropdownMenuSubTrigger and DropdownMenuSubContent (placement defaults to right-start).

Keyboard

KeyAction
Enter / Space / ↓On the trigger: opens the menu with the first item focused.
↑On the trigger: opens the menu with the last item focused.
↓ / ↑Next / previous item (wraps around).
Home / EndFirst / last item.
A–ZTypeahead: jumps to the item that starts with what you type.
Enter / SpaceChooses the item.
→On a submenu item: opens it and focuses its first item.
← / EscIn a submenu: closes it. Esc in the main menu closes it and returns focus to the trigger.
TabCloses the menu.

Accessibility

  • Follows the WAI-ARIA menu button pattern: role="menu" with menuitem, menuitemcheckbox and menuitemradio items.
  • The trigger has aria-haspopup="menu", aria-expanded and aria-controls; the menu is labelled by the trigger.
  • Opened with the keyboard, focus lands on an item; opened with the pointer, on the menu itself. The highlight follows the pointer and the keyboard.
  • Focus returns to the trigger on close, except after a click outside.

Motion

  • Open: pops from the trigger side, scale .96, 4px travel (150ms, ease-out).
  • Close: 160ms fade. Submenus use the same pop from their own side.
  • Reduced motion: it appears and disappears without movement.