Dropdown
A menu composed from parts: actions with shortcuts, groups, submenus, and checkbox and radio choices.
Usage
import {
Dropdown,
DropdownContent,
DropdownItem,
DropdownTrigger,
} from 'nyctoui/dropdown'
<Dropdown>
<DropdownTrigger render={<Button />}>Options</DropdownTrigger>
<DropdownContent>
<DropdownItem>Rename…</DropdownItem>
<DropdownItem variant="danger">Delete</DropdownItem>
</DropdownContent>
</Dropdown>DropdownTrigger renders a plain <button>. Pass render={<Button />} for a styled one; the button shows its pressed state while the menu is open.
Good for
- A row’s “More” menu in a file list, with Rename, Move and Delete.
- An account menu in an app header, with profile, settings and sign out.
- View options in a table toolbar, with checkbox items for visible columns and radio items for sort order.
- A “Share” menu with a submenu of people or channels.
Anatomy
<Dropdown>
<DropdownTrigger />
<DropdownContent>
<DropdownItem>
<DropdownShortcut>
<Kbd />
</DropdownShortcut>
</DropdownItem>
<DropdownSeparator />
<DropdownGroup>
<DropdownLabel />
<DropdownCheckboxItem />
</DropdownGroup>
<DropdownRadioGroup>
<DropdownRadioItem />
</DropdownRadioGroup>
<DropdownSub>
<DropdownSubTrigger />
<DropdownSubContent />
</DropdownSub>
</DropdownContent>
</Dropdown>Examples
Submenus
A submenu opens on hover or with Right, and takes the same parts as the root menu.
Checkbox and radio items
Choices keep the menu open, so several can be changed in a row. Both support controlled and uncontrolled use.
Best practices
- Write each item as a short action: “Rename”, “Duplicate”, “Move to…”.
- Group related items with
DropdownGroupandDropdownSeparatoronce the menu passes a handful of items, and keep destructive ones at the end. - Show shortcuts with
DropdownShortcutfor actions that have them. - Keep the main actions out of the menu, on visible buttons; the menu is for the rest.
- Use a dropdown for site navigation. Use links in a sidebar or a header.
- Put more than ten or twelve items in one menu without groups.
- Use a dropdown to choose a form value. That’s a select.
API reference
Dropdown
Wraps ui-sdk’s Menu and accepts its props, such as onAction. Renders no element.
| Prop | Type | Default |
|---|---|---|
open / defaultOpen / onOpenChangeControl whether the menu is open. | boolean · (open, details) => void | — |
modalpointer: an outside press only closes the menu. true also locks scroll and makes the page inert. | boolean | 'pointer' | 'pointer' |
DropdownTrigger
ui-sdk’s MenuTrigger. Carries data-open while its menu is open.
| Prop | Type | Default |
|---|---|---|
renderReplaces the <button>, e.g. render={<Button />}. | ReactElement | function | — |
DropdownContent
The popup, in the top layer.
| Prop | Type | Default |
|---|---|---|
bareDrops the padded, scrolling list around the children, for a panel such as an EmojiPicker. | boolean | false |
sideSide of the trigger to open on. | 'top' | 'bottom' | 'left' | 'right' | 'bottom' |
alignAlignment along that side. | 'start' | 'center' | 'end' | 'start' |
sideOffsetGap between trigger and popup, in pixels. | number | 6 |
alignOffsetShift along the alignment axis, in pixels. | number | 0 |
collisionPaddingSpace kept from the viewport edges. | number | 8 |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DropdownItem
An action. Closes the menu when chosen.
| Prop | Type | Default |
|---|---|---|
iconIcon shown before the label, tinted quieter than the label. | ReactNode | — |
variantdanger tints the item red for destructive actions. | 'default' | 'danger' | 'default' |
onClickCalled when the item is chosen by pointer or keyboard. | (event) => void | — |
disabledKeeps the item from being chosen. | boolean | false |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DropdownLinkItem
A DropdownItem rendered as a link. Renders an <a>.
| Prop | Type | Default |
|---|---|---|
hrefWhere the link goes. | string | — |
renderReplaces the <a>, e.g. render={<Link to="/" />}. | ReactElement | function | — |
closeOnSelectClose the menu when the link is followed. | boolean | true |
iconIcon shown before the label, tinted quieter than the label. | ReactNode | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DropdownCheckboxItem
Toggles independently and keeps the menu open.
| Prop | Type | Default |
|---|---|---|
checked / defaultCheckedWhether the item is ticked. | boolean | — |
onCheckedChangeCalled when the item is toggled. | (checked, details) => void | — |
iconIcon shown before the label, tinted quieter than the label. | ReactNode | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DropdownRadioGroup
Holds radio items; one value is chosen at a time.
| Prop | Type | Default |
|---|---|---|
value / defaultValueThe chosen value. | any | — |
onValueChangeCalled when another item is chosen. | (value, details) => void | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DropdownRadioItem
One choice in a DropdownRadioGroup.
| Prop | Type | Default |
|---|---|---|
valueThe value this item chooses. | any | — |
closeOnSelectClose the menu once chosen, for single-choice menus. | boolean | false |
iconIcon shown before the label, tinted quieter than the label. | ReactNode | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DropdownSub
A submenu. Takes open, defaultOpen, onOpenChange and delay.
DropdownSubTrigger
The item that opens a submenu. The arrow is built in.
| Prop | Type | Default |
|---|---|---|
iconIcon shown before the label, tinted quieter than the label. | ReactNode | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DropdownSubContent
The submenu popup. Takes the same props as DropdownContent.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
DropdownGroup, DropdownLabel, DropdownSeparator, DropdownShortcut
Grouping, a group heading, a hairline divider, and a hint aligned to the end of an item. Put Kbds in the hint for a shortcut, or plain text for a time or a count. Each takes sx.