DropdownMenu
A list of actions behind a button: Rename, Duplicate, Delete. It opens on the raised surface with items the height and look of Select's options, and moves with the arrow keys. Items can carry a leading icon and a shortcut, turn options on and off, pick one of several, or open a submenu.
Preview
Usage
When to use
- Several actions on one item behind one button: Rename, Duplicate, Delete.
- Options that turn on and off, or one of several, in a toolbar or a header.
When not to use
- Picking a value in a form. Use Select.
- Fields or other controls. Use Popover.
- The main action of a screen, or the only way to do a common action. Use Button.
Platform support
What each platform has, from the spec. A selected platform is highlighted.
| Name | Web | iOS | Android | Note |
|---|---|---|---|---|
| open | Yes | Yes | Yes | |
| defaultOpen | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| onOpenChange | Yes | Yes | Yes | |
| modal | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| side | Yes | Yes | Yes | |
| align | Yes | Yes | Yes | |
| sideOffset | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| loop | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| destructive | Yes | No | No | Only on web. Not generated for iOS and Android. |
| disabled | Yes | No | No | Only on web. Not generated for iOS and Android. |
| inset | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| leadingIcon | Yes | No | No | Only on web. Not generated for iOS and Android. |
| shortcut | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| asChild | Yes | Deferred | Deferred | Not generated for iOS and Android. |
| sections | No | Yes | Yes | Only on iOS, Android. |
| value of keyboard: ArrowUp, ArrowDown | Yes | Deferred | Deferred | |
| value of keyboard: Home, End | Yes | Deferred | Deferred | |
| value of keyboard: ArrowRight | Yes | Deferred | Deferred | |
| value of keyboard: ArrowLeft | Yes | Deferred | Deferred | |
| value of keyboard: A letter | Yes | Deferred | Deferred |
Variants
side
Set on DropdownMenuContent. The side of the trigger it opens on. It flips when there is no room.
align
Set on DropdownMenuContent. start lines the menu up with the trigger's start edge; end for a trigger at the end of a row.
Examples
Actions
Groups and choices
A checkbox item turns an option on or off; radio items pick one. In an app, pair checked with onCheckedChange and value with onValueChange.
Links
asChild makes a link the item, for actions that go to another page.
Submenus
DropdownMenuSub nests a menu behind an item. Move the pointer diagonally from an item to its submenu: the items it crosses on the way stay quiet.
Do and don't
Do
- Start each item with a verb: Rename, Duplicate, Delete.
- Put destructive actions last, after a separator, and confirm them with an AlertDialog.
- Name an icon-only trigger with aria-label, such as More actions.
- Use a submenu for a short list of related choices (Move to, Export as), one level deep.
Don't
- Don't use it to pick a value in a form; use Select.
- Don't put fields or other controls in it; use Popover.
- Don't hide the only way to do a common action in a menu; give it a Button.
Props
| Name | Type | Values | Default | Description |
|---|---|---|---|---|
| open | boolean | - | - | Set on DropdownMenu or DropdownMenuSub. Whether it is open, when you control it. Pair it with onOpenChange. |
| defaultOpen | boolean | - | false | Set on DropdownMenu. Opens it on first render, when you don't control it. Not generated for iOS and Android. |
| onOpenChange | function | - | - | Set on DropdownMenu or DropdownMenuSub. Called with true or false when it opens or closes. |
| modal | boolean | - | true | Set on DropdownMenu. true keeps the rest of the page out of reach (no hover, no scroll) while the menu is open. Not generated for iOS and Android. |
| side | enum | top | right | bottom | left | bottom | Set on DropdownMenuContent. The side of the trigger it opens on. It flips when there is no room. |
| align | enum | start | center | end | start | Set on DropdownMenuContent. start lines the menu up with the trigger's start edge; end for a trigger at the end of a row. |
| sideOffset | number | - | 4 | Set on DropdownMenuContent. Space between the trigger and the menu, in px. 4 is spacing-xs. Not generated for iOS and Android. |
| loop | boolean | - | false | Set on DropdownMenuContent. The arrow keys wrap from the last item to the first. Not generated for iOS and Android. |
| destructive | boolean | - | false | Set on DropdownMenuItem. Danger text for an action that deletes or can't be undone. Confirm it with an AlertDialog. On native, set destructive on WerewolfMenuItem. Only on web. Not generated for iOS and Android. |
| disabled | boolean | - | false | Set on an item. It can't be highlighted or run, and the arrow keys skip it. On native, set disabled on WerewolfMenuItem. Only on web. Not generated for iOS and Android. |
| inset | boolean | - | false | Set on DropdownMenuItem, DropdownMenuSubTrigger or DropdownMenuLabel. Lines the label up with items that have an icon or a check. Not generated for iOS and Android. |
| leadingIcon | node | - | - | Set on DropdownMenuItem or DropdownMenuSubTrigger. A decorative 16px icon before the label: <IconPencil size={16} />. On native, pass leadingIcon on WerewolfMenuItem (iOS Menu displays Image or Label). Only on web. Not generated for iOS and Android. |
| shortcut | string | - | - | Set on DropdownMenuItem. The keyboard shortcut at the end: ⌘D. The app handles the key itself. Not generated for iOS and Android. |
| asChild | boolean | - | false | Set on DropdownMenuItem. Renders the child (a link) as the item, for actions that go to another page. leadingIcon and shortcut don't apply; put the icon inside the link. Not generated for iOS and Android. |
| sections required | WerewolfMenuSection[] | - | - | Sections of menu items (WerewolfMenuSection with optional title and WerewolfMenuItem entries). Native only; the web builds them from DropdownMenuItem, DropdownMenuLabel and DropdownMenuSeparator. Only on iOS, Android. |
Not generated: DropdownMenuCheckboxItem, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger.
Slots
| Name | Required | Description |
|---|---|---|
| trigger | yes | DropdownMenuTrigger with asChild around a Button. |
| content | yes | DropdownMenuContent with one DropdownMenuItem per action, in the order users need them, destructive ones last. Group long menus with DropdownMenuLabel and DropdownMenuSeparator. Nest a DropdownMenuSub (a DropdownMenuSubTrigger and a DropdownMenuSubContent) for a group of related actions behind one item. |
Anatomy
| Part | Description |
|---|---|
| root | DropdownMenuItem: one action. The md control height (32px on mouse, 36px on touch), inner corners, 14px primary text, a leading icon in the primary icon color, the neutral hover overlay when highlighted. destructive turns the text and icon to the danger text color. |
| destructive | A destructive DropdownMenuItem (destructive): danger text on the same neutral row and highlight. Classes land on the item. |
| destructiveIcon | The leading icon of a destructive item, in the danger text color (there is no danger icon token). |
| menu | DropdownMenu. Holds the open state; renders nothing itself. |
| trigger | DropdownMenuTrigger: the button that opens the menu, usually a Button with asChild. |
| content | DropdownMenuContent: the floating list on the raised surface, at least 192px wide, the same surface as Select's list. It scrolls when it is taller than the screen minus spacing-sm at the top and bottom. |
| icon | The leading icon of an item (leadingIcon), Tabler icons, 16px. |
| indicator | The check of a DropdownMenuCheckboxItem (Tabler check, 16px) or the 6px dot of a DropdownMenuRadioItem, before the label. |
| groupLabel | DropdownMenuLabel: the heading of a group, one step smaller than an item, in secondary text. |
| separator | DropdownMenuSeparator: a line across the full menu between two groups. |
| shortcut | DropdownMenuShortcut: a compact small Kbd at the end of the row, with UI type. It is a hint; the app handles the keys. |
| subTrigger | DropdownMenuSubTrigger: an item that opens a submenu, inside DropdownMenuSub. Same row as an item, with a chevron at the end. It keeps the hover overlay while its submenu is open. |
| subIcon | The chevron at the end of a DropdownMenuSubTrigger (Tabler chevron-right, 16px) in the secondary icon color. It points left in right-to-left text. |
| subContent | DropdownMenuSubContent: the submenu, the same surface as DropdownMenuContent. It opens spacing-xs beside its item, with its first item lined up with it, and flips to the other side when there is no room. |
Accessibility
Role: menu
| Keys | Action |
|---|---|
| Space, Enter, ArrowDown | On the trigger: opens the menu and focuses the first item. |
| ArrowUp, ArrowDown | Moves between items, skipping disabled ones. With loop, it wraps from the last to the first. |
| Home, End | Focuses the first or the last item. |
| Enter, Space | Runs the item and closes the menu. On a checkbox or radio item, turns it on or picks it. |
| ArrowRight | On an item with a submenu: opens the submenu and focuses its first item. Enter and Space open it too. In right-to-left text, ArrowLeft. |
| ArrowLeft | In a submenu: closes it and returns focus to the item that opened it. In right-to-left text, ArrowRight. |
| Escape | Closes the menu and returns focus to the trigger. |
| A letter | Focuses the next item whose label starts with it. |
- The trigger gets aria-haspopup and aria-expanded; the list is a menu of menuitem, menuitemcheckbox and menuitemradio.
- Name an icon-only trigger with aria-label: More actions.
- A destructive item says what it destroys (Delete project) and opens an AlertDialog; danger text is not the only warning.
- The shortcut text is read with the label. The app handles the shortcut itself; the menu only shows it.
- A group heading (DropdownMenuLabel) is not focusable.
- An item with a submenu (DropdownMenuSubTrigger) gets aria-haspopup and aria-expanded, and its submenu is a menu of its own.
- Safe triangle: on the way from an item to its open submenu, while the pointer stays inside the triangle from where it left the item to the submenu's near top and bottom corners, the items it crosses don't highlight and the submenu stays open. When the pointer rests for 150ms, the item under it highlights as usual.
Install
npx werewolf-ui add dropdown-menuRun npx werewolf-ui init once in your app before adding components. Init sets up tokens, their CSS import and agent rules. Add installs this component and its dependencies while preserving your theme. See Installation for requirements and the alternative registry setup.