About the shadcn/ui Dropdown Menu Component

The Dropdown Menu component is part of shadcn/ui — a collection of accessible, copy-paste React components built with Radix UI and Tailwind CSS. Install it with `npx shadcn@latest add dropdown-menu` and copy it directly into your project.

Dropdown Menu Component — Frequently Asked Questions

How do I open a shadcn Dropdown Menu programmatically?

Use `<DropdownMenu open={open} onOpenChange={setOpen}>` with state. Set `open={true}` to force it open, useful for tutorial highlights or keyboard shortcuts.

How do I add keyboard shortcuts to Dropdown Menu items?

Add `<DropdownMenuShortcut>⌘K</DropdownMenuShortcut>` inside `<DropdownMenuItem>`. This renders the shortcut hint—you'll need to implement the actual keyboard handler separately.

How do I close the Dropdown after clicking an item?

By default, clicking a `<DropdownMenuItem>` closes the menu. If using `onSelect` to prevent close, use `event.preventDefault()` inside the handler.

Dropdown Menu Component - shadcn/ui Examples | Shadcn Store