DropdownMenu
A menu of commands belonging to the control that opens it ā how one row or one toolbar offers eight actions without growing eight buttons.
Default
A kebab on the thing the commands act on, which is the scope a reader will read into it. `DropdownMenuLabel` names that scope out loud, `DropdownMenuGroup` keeps the related verbs together, and `DropdownMenuShortcut` states the key without pretending to be one ā it is a label, so bind the accelerator yourself.
Usage
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuPortal,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuShortcut,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
DropdownMenuTrigger,
} from '@oceanic-hub/brand-system'<DropdownMenu>
<DropdownMenuTrigger>ā¦</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>ā¦</DropdownMenuLabel>
<DropdownMenuSeparator>ā¦</DropdownMenuSeparator>
<DropdownMenuGroup>
<DropdownMenuItem>
<DropdownMenuShortcut>ā¦</DropdownMenuShortcut>
</DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuItem>ā¦</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>Composition
Use the following composition to build a DropdownMenu:
DropdownMenu
āāā DropdownMenuTrigger
āāā DropdownMenuContent
āāā DropdownMenuLabel Ć2
āāā DropdownMenuSeparator Ć2
āāā DropdownMenuGroup
ā āāā DropdownMenuItem Ć3
ā āāā DropdownMenuShortcut
āāā DropdownMenuItem Ć4
āāā DropdownMenuSub Ć2
ā āāā DropdownMenuSubTrigger
ā āāā DropdownMenuSubContent
ā āāā DropdownMenuItem Ć3
ā āāā DropdownMenuSeparator
āāā DropdownMenuCheckboxItem Ć3
āāā DropdownMenuRadioGroup Ć2
āāā DropdownMenuRadioItem Ć3Items act. Anything that navigates should render as the host's own link through
asChild ā the package imports no router, and a menu item that fakes a link with an onSelect
loses middle-click, open-in-new-tab and the status bar.
The trigger is the scope. A kebab on a row says these act on this row, and a reader will believe
it; putting a screen-wide command there is the one mistake this component makes easy. Commands
that always apply belong on a Menubar, and if the reader is already pointing at the thing, a
ContextMenu costs no pixels at all where a dropdown costs a button on every line. All three
draw as one object, and since @OCE-1870 that is true of the rendered pixels and not only of the
intent: the same ground, the same hairline, the same 6px, the same min-w-40 floor, and the same
pop in and out of the owned motion scale.
DropdownMenuCheckboxItem and DropdownMenuRadioItem let a menu double as a small view
switcher, which is usually better than a settings dialog for two or three toggles. They carry an
indicator column rather than a flex gap, which is why inset exists on the plain parts and
deliberately not on those two: it aligns an item that has no indicator with the ones that do, and
on an item that already has the column it would only double the indent.
The content portals itself, so a menu never renders inline. That is what lets one open out of a
card with a clipped overflow, and it is also why the menu is not inside your form's DOM ā a menu
item that must submit needs its own handler rather than a type="submit".
variant="destructive" is refused. Upstream marks a dangerous item by painting its label
red. core-layer.md: "Never write a status tone as a text colour" ā the tones are bright
mid-tones built to work as fills, and text-stuck measured 4.03:1, below AA, on Button before
@OCE-1747 moved that label back to ink. Severity is carried by copy: "Delete 12 contacts
permanently" is unambiguous, a red item reading "Delete" is not. The Destructive actions
section shows what to do instead.
Three upstream examples are folded rather than duplicated, so nothing is silently missing: Shortcuts is in the lead demo; Checkboxes Icons and Radio Icons are the point made in With icons ā a checkable item has no gap of its own, so an icon inside one needs its own spacing ā and Complex is a composition of the sections below with no API in it that they do not already show.
RTL is not supported. Upstream ships an RTL demo; we do not, because nothing in this package
has ever been laid out or measured right-to-left. The refusal is written down in pairings.json
under direction.
Submenus
Nest a branch under DropdownMenuSub when a verb needs an object ā "Move to", "Export as" ā so the first level stays a scannable list of what you can do rather than of what you can do to what. Keep it to one level; a second is a tree being navigated with a mouse, and that is a dialog.
Checkbox items
Independent toggles, for the two or three view switches that would be a heavy settings dialog. Selecting any item closes the menu ā that is the default and it is right for a command, wrong for a checkbox a reader wants to flip three of, so these call preventDefault() on select to hold it open. Hold the checked state yourself: the item renders what you give it and reports the next value, it does not remember.
Radio items
One live value out of a short exclusive set. Reach for it over checkboxes when picking a second option must un-pick the first, and let the menu close on select ā the reader is done, and closing is the confirmation. DropdownMenuLabel names the axis, without which a reader has to infer from the values why they cannot all be on.
With icons
Every item takes an icon or none do, so the labels share one left edge. DropdownMenuItem supplies the gap, so a plain item needs no spacing class ā but a checkbox or radio item does, because its left inset is an indicator column and not a flex gap. That is the whole content of upstream's separate Checkboxes Icons and Radio Icons examples, so they are made here once.
Destructive actions
Upstream paints the item red; this package does not, because a status tone is a fill and never text. The danger is carried by the label ā "Delete 12 contacts permanently" names the count and the finality ā and by a separator that puts the action outside the group above it, so nobody lands on it by momentum. An item never confirms: anything unrecoverable opens AlertDialog rather than firing on select.
Account menu
An avatar makes a good trigger precisely because it already says whose account this is, so the menu does not have to repeat it in a heading ā it uses DropdownMenuLabel to say which identity, which is the thing a reader with two logins actually needs. Wrap the avatar in a Button rather than making the image clickable: the trigger has to be focusable and named.
API Reference
See the DropdownMenu API page for every prop of every part, with types, defaults and the contract that pins them.