Dropdown menu

Free

The base for every menu, select and picker: it grows out of its trigger, a highlight glides between rows, and rows can be actions, choices that say what they cost, checkboxes, switches or submenus.

npx shadcn@latest add https://pixilui.com/r/dropdown-menu.json

Preview

A highlight glides between rows, and each row's icon plays as it lands.
Menu

When to use

Use it when

  • A run's actions behind a ••• button, with a submenu for assigning.
  • Picking a model, where each option says what it costs, with search.
  • Switching workspaces, filtering by several statuses, or tools that switch on and off in place.

Use something else when

  • Two or three options always visible: use a segmented control or radios.
  • A form's field among many options: use a select.
  • A command palette across the app: use the command menu.

Installation

Terminal
npx shadcn@latest add https://pixilui.com/r/dropdown-menu.json

Adds dropdown-menu.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.

Usage

example.tsx
import { DropdownMenu } from "@/components/pixilui/dropdown-menu";

<DropdownMenu
  aria-label={aria-label}
  groups={groups}
  trigger={trigger}
  onValueChange={onValueChange}
/>

The menu is 232px by default (width sets it); align="end" lines it up with the trigger's right edge.

API reference

PropTypeDefault
aria-labelRequiredstring–The menu's accessible name.
groupsRequiredDropdownMenuGroup[]NONEThe rows, in groups: each with an optional label, separated by a gap when it has none.
triggerRequiredReactElement | ((state: DropdownMenuTriggerState) => ReactElement)–The trigger, a locked Button; or a function of the menu's state, to show the picked value or the count.
select"single" | "multi"–single: picking checks the row (a check, or a ring with dots). multi: rows toggle and the menu stays open.
ringboolean–single choice: show a ring instead of a check (workspaces).
widthstring–The menu's width (232px by default; submenus 212px).
search{ placeholder: string; "aria-label": string; empty: string; icon?: ReactNode }–A search row first: it filters the rows and says when nothing matches.

Also takes every native <div> attribute, and a ref.

Keyboard

↓ Enter SpaceOn the trigger, opens the menu and moves focus into it (or its search).
↑ ↓Moves the highlight, wrapping at the ends; Home and End jump to them.
EnterPicks the highlighted row; a switch or multi choice row flips and the menu stays open.
→ ←Opens a submenu and moves into it; steps back to its row.
EscCloses the menu (or steps out of a submenu) and returns focus to the trigger.
TabCloses the menu.

Accessibility

  • The trigger has aria-haspopup="menu" and aria-expanded; the menu follows the highlight with aria-activedescendant.
  • Rows are menuitem, menuitemradio or menuitemcheckbox with aria-checked; a switch row's switch is aria-hidden and the row carries the state.
  • Only one menu is open at a time; an outside click closes it.
  • Keys win until the pointer really moves, so a menu closing under a resting pointer never steals the keyboard's highlight.

Motion

  • Opens from .96 and fades in over 200ms while its rows rise 3px, 25ms apart; closes in 120ms the same way back.
  • The highlight glides to its row in 150ms, and the row's animated icon plays as it lands.
  • A submenu opens after an 80ms hover intent; a safe triangle keeps it open while the pointer heads to it.
  • Reduced motion: instant.

PixilUI Pro opens soon. The first 20 licenses are $99.