Core components / Dropdown menus
Dropdown menu
A list of actions that floats from a button: a tray holding a raised card of items, mono group labels, shortcuts in mono on the right, submenus beside their item and a red item for the destructive one. Fully keyboard driven, on the S to XXL ladder.
Code
The component itself, ready to drop into your project. Switch between React, Vue and plain HTML; every version uses the same Tailwind classes on Ochre's tokens.
Installation
Examples
Account menu
Who's signed in on the tray above the card, and a theme submenu.
Sort options
A mono label on the tray, one ticked choice, and rarer settings in a submenu.
Sizes
S, M, L, XL and XXL items, matching the Button that opens them.
Motion
Built on Ochre's ease-out curves. With reduced motion switched on, everything still works, it just doesn't move.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| trigger | ReactElement | – | Usually a Button. It gets aria-haspopup, aria-expanded and the click and arrow-key handlers. |
| items | DropdownMenuEntry[] | – | Items, { type: "label" } group labels and { type: "separator" } lines, in order. |
| size | "s" | "m" | "l" | "xl" | "xxl" | "s" | Item height 32, 40, 48, 56 or 64 pixels, matching the Button beside it. |
| item.label / icon / description | ReactNode | – | What the item says, an optional leading icon and a muted second line. |
| item.dot | MenuTint | – | A colour dot before the label: "red", "blue", "green" and the other tints. |
| item.shortcut | string[] | – | Keys shown on the right in mono: ["⌘", "D"]. Bind them in your app; a single digit also picks the item while the menu is open. |
| item.trailing | ReactNode | – | Anything else on the right in mono, such as a date or a count. |
| item.onSelect / href | () => void, string | – | What it does. The menu closes and focus returns to the trigger. |
| item.danger / disabled | boolean | – | Red for the destructive item; disabled items are skipped by the keyboard. |
| item.checked / radio / check | boolean, boolean, "tick" | "box" | – | A tick (or a checkbox at the start with check="box"). Checked items keep the menu open; radio ones close it. |
| item.items | DropdownMenuEntry[] | – | A submenu that opens beside the item on hover, → or ↵, and closes with ← or esc. |
| align / side | "start" | "end", "bottom" | "top" | "start", "bottom" | Which edge of the trigger the menu lines up with, and whether it opens below or above. |
| header / footer | ReactNode | – | Content on the tray above or below the card. Tab reaches buttons placed there. |
| open / onOpenChange | boolean, (open) => void | – | Control it yourself. Leave both out and the trigger handles it. |
| point | { x: number; y: number } | – | Opens at a point in the viewport instead of beside the trigger, as Context menu does. |
| label | string | – | Accessible name for the menu. |
Usage
Use it for
- Secondary actions on an object: the ⋯ button on a row, card or page header.
- Account and workspace menus, with who's signed in on the tray.
- Sort and view options as ticked items, with rarer settings in a submenu.
Avoid
- Choosing a value for a form field: use a Select.
- The page's main action: give it its own Button.
- Menus longer than about ten items; group them, move the rest into a submenu or use a Command menu.