Captain UI

Dropdown menu

Scales out of its trigger, one highlight slides between items, and a submenu stays open while your pointer cuts the corner toward it.

npx shadcn@latest add https://captain-ui.vercel.app/r/dropdown-menu.json

Fix invoice rounding

Run 1187 in billing-service, 4m 12s, $0.84

Usage

import {
  DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem,
  DropdownMenuCheckboxItem, DropdownMenuSub, DropdownMenuSubTrigger, DropdownMenuSubContent,
} from "@/components/ui/dropdown-menu"

<DropdownMenu>
  <DropdownMenuTrigger>Options</DropdownMenuTrigger>
  <DropdownMenuContent>
    <DropdownMenuItem shortcut="⌘R" onSelect={rerun}>Rerun</DropdownMenuItem>
    <DropdownMenuSub>
      <DropdownMenuSubTrigger>Move to project</DropdownMenuSubTrigger>
      <DropdownMenuSubContent>…</DropdownMenuSubContent>
    </DropdownMenuSub>
    <DropdownMenuCheckboxItem checked={notify} onCheckedChange={setNotify}>Notify me</DropdownMenuCheckboxItem>
  </DropdownMenuContent>
</DropdownMenu>

Props

PropTypeDefaultWhat it does
DropdownMenu openbooleanControlled open state. Pair with onOpenChange.
DropdownMenuContent align"start" | "end""start"Which edge of the trigger the menu lines up with. Flips above when there is no room below.
DropdownMenuItem onSelect() => voidRuns on click, Enter or Space, then the menu closes.
DropdownMenuItem shortcutstringShown at the right in tabular figures.
DropdownMenuItem tone"default" | "danger""default"Danger for destructive actions.
DropdownMenuItem textValuestringTypeahead text when children are not plain text.
DropdownMenuCheckboxItem checkedbooleanToggles without closing the menu.
DropdownMenuSubcomponentWraps a SubTrigger and SubContent. Opens on hover, Enter or the right arrow.

Keyboard

↑ ↓
Move
Home / End
First or last item
Enter / Space
Select
→ / ←
Open or close a submenu
A to Z
Jump to the item that starts with what you type
Esc
Close and return focus

Accessibility

  • role=menu with menuitem and menuitemcheckbox, aria-checked and aria-expanded on submenu triggers.
  • Roving focus: hovering an item focuses it, so pointer and keyboard share one highlight.
  • Opening from the keyboard focuses the first item; closing returns focus to the trigger.
  • Tab closes the menu instead of trapping focus.