Skip to content
synccn

Dropdown Menu

Actions, checkboxes, labels and shortcuts with arrow-key navigation.

Installation

$ pnpm dlx shadcn@latest add @synccn/dropdown-menu

First time in this project? Connect synccn with one command.

Usage

import { DropdownMenu } from "@/components/ui/dropdown-menu";<DropdownMenu trigger={<Button>Menu</Button>} items={items} />

API reference

Generated from the component's TypeScript types, so it always matches the code.

DropdownMenu

items: [ { label, icon?, shortcut?, onSelect?, destructive?, disabled? } | { type: "separator" } | { type: "label", label } | { type: "checkbox", label, checked, onCheckedChange } ]

  • triggerrequired
    React.ReactNode

    Element that opens the menu.

  • itemsrequired
    DropdownMenuItem[]

    Menu entries.

  • align
    "start" | "end"

    Default "start"

    Which edge of the trigger the menu lines up with.

  • contentClassName
    string

    Extra classes for the menu panel.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseAutoSide (flips to the side with room), useClickOutside (closes on an outside click), useEscape (closes on Escape), usePresence (animates in and out)

npm packages

Keyboard

  • ↓or↑Move between items
  • HomeorEndJump to the first or last item
  • EnterorSpaceRun the item, or toggle a checkbox item
  • EscClose the menu
  • TabClose the menu and move focus on

Accessibility

  • Uses the menu role; checkbox items expose aria-checked.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: it, menu, separator
  • ARIA attributes: aria-checked, aria-disabled
  • Keys handled: ArrowUp, ArrowDown, Home, End, Enter, Tab, Space
  • Closes with Escape
  • Closes when you click or tap outside
  • Flips to whichever side has room, so it stays on screen