Dropdown menu
A list of actions with checkbox, radio and nested items.
A list of actions with checkbox, radio and nested items.
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline">Options</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start">
<DropdownMenuLabel>Project</DropdownMenuLabel>
<DropdownMenuItem shortcut="⌘D" onSelect={duplicate}>Duplicate</DropdownMenuItem>
<DropdownMenuItem shortcut="⌘E">Rename</DropdownMenuItem>
<DropdownMenuItem>Share</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem variant="danger">Delete</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>The same component at all four levels. Pick the one that fits your project; they share tokens, so they mix.
npm i junco @junco/tailwindimport { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator } from "junco";
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline">Options</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuLabel>Account</DropdownMenuLabel>
<DropdownMenuItem shortcut="⌘P">Profile</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem variant="danger">Log out</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>Toggle settings and pick one option without leaving the menu.
DropdownMenu#openonOpenChangemodal| Prop | Type | Default |
|---|---|---|
openControlled open state. | boolean | – |
onOpenChangeCalled when the menu opens or closes. | (open: boolean) => void | – |
modalBlocks the rest of the page while open. | boolean | true |
DropdownMenuContent#alignsidesideOffset| Prop | Type | Default |
|---|---|---|
alignAlignment against the trigger. | "start" | "center" | "end" | "center" |
sidePreferred side; flips when there isn't room. | "top" | "right" | "bottom" | "left" | "bottom" |
sideOffsetGap from the trigger in px. | number | 6 |
DropdownMenuItem#variantshortcutinsetonSelectdisabledasChild| Prop | Type | Default |
|---|---|---|
variantdanger for destructive actions. | "default" | "danger" | "default" |
shortcutTrailing keyboard hint. Visual only: wire the shortcut yourself. | string | – |
insetIndent to line up with checkbox and radio items. | boolean | – |
onSelectRuns on click or Enter. event.preventDefault() keeps the menu open. | (event) => void | – |
disabledSkipped by the keyboard and not selectable. | boolean | – |
asChildRender your own element (a router Link) as the item. | boolean | – |
DropdownMenuCheckboxItem / DropdownMenuRadioItem#checkedvalue| Prop | Type | Default |
|---|---|---|
checkedCheckbox item state, with onCheckedChange. | boolean | – |
valueRadio item value, inside a DropdownMenuRadioGroup with value and onValueChange. | string | – |
| Key | Action |
|---|---|
| Enter | Opens the menu from the trigger, or selects the focused item. |
| Space | Same as Enter. |
| ↓↑ | Moves between items. |
| → | Opens a submenu. |
| ← | Closes a submenu. |
| A–Z | Jumps to the item starting with that letter. |
| Esc | Closes the menu and returns focus to the trigger. |