Components

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

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

Do
  • Write each item as a short action: “Rename”, “Duplicate”, “Move to…”.
  • Group related items with DropdownGroup and DropdownSeparator once the menu passes a handful of items, and keep destructive ones at the end.
  • Show shortcuts with DropdownShortcut for actions that have them.
  • Keep the main actions out of the menu, on visible buttons; the menu is for the rest.
Don’t
  • 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

Wraps ui-sdk’s Menu and accepts its props, such as onAction. Renders no element.

PropTypeDefault
open / defaultOpen / onOpenChange
Control whether the menu is open.
boolean · (open, details) => void—
modal
pointer: an outside press only closes the menu. true also locks scroll and makes the page inert.
boolean | 'pointer''pointer'

ui-sdk’s MenuTrigger. Carries data-open while its menu is open.

PropTypeDefault
render
Replaces the <button>, e.g. render={<Button />}.
ReactElement | function—

The popup, in the top layer.

PropTypeDefault
bare
Drops the padded, scrolling list around the children, for a panel such as an EmojiPicker.
booleanfalse
side
Side of the trigger to open on.
'top' | 'bottom' | 'left' | 'right''bottom'
align
Alignment along that side.
'start' | 'center' | 'end''start'
sideOffset
Gap between trigger and popup, in pixels.
number6
alignOffset
Shift along the alignment axis, in pixels.
number0
collisionPadding
Space kept from the viewport edges.
number8
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

An action. Closes the menu when chosen.

PropTypeDefault
icon
Icon shown before the label, tinted quieter than the label.
ReactNode—
variant
danger tints the item red for destructive actions.
'default' | 'danger''default'
onClick
Called when the item is chosen by pointer or keyboard.
(event) => void—
disabled
Keeps the item from being chosen.
booleanfalse
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

A DropdownItem rendered as a link. Renders an <a>.

PropTypeDefault
href
Where the link goes.
string—
render
Replaces the <a>, e.g. render={<Link to="/" />}.
ReactElement | function—
closeOnSelect
Close the menu when the link is followed.
booleantrue
icon
Icon shown before the label, tinted quieter than the label.
ReactNode—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

Toggles independently and keeps the menu open.

PropTypeDefault
checked / defaultChecked
Whether the item is ticked.
boolean—
onCheckedChange
Called when the item is toggled.
(checked, details) => void—
icon
Icon shown before the label, tinted quieter than the label.
ReactNode—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

Holds radio items; one value is chosen at a time.

PropTypeDefault
value / defaultValue
The chosen value.
any—
onValueChange
Called when another item is chosen.
(value, details) => void—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

One choice in a DropdownRadioGroup.

PropTypeDefault
value
The value this item chooses.
any—
closeOnSelect
Close the menu once chosen, for single-choice menus.
booleanfalse
icon
Icon shown before the label, tinted quieter than the label.
ReactNode—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

A submenu. Takes open, defaultOpen, onOpenChange and delay.

The item that opens a submenu. The arrow is built in.

PropTypeDefault
icon
Icon shown before the label, tinted quieter than the label.
ReactNode—
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

The submenu popup. Takes the same props as DropdownContent.

PropTypeDefault
sx
StyleX styles merged after the built-in ones.
StyleXStyles—

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.