Dropdown Menu

Displays a menu to the user triggered by a button.

Installation

bash
npx shadcn@latest add dropdown-menu

Import

import {  DropdownMenu,  DropdownMenuTrigger,  DropdownMenuContent,  DropdownMenuItem,  DropdownMenuCheckboxItem,  DropdownMenuRadioItem,  DropdownMenuLabel,  DropdownMenuSeparator,  DropdownMenuShortcut,  DropdownMenuGroup,  DropdownMenuSub,  DropdownMenuSubContent,  DropdownMenuSubTrigger,  DropdownMenuRadioGroup,} from "@/components/ui/dropdown-menu"

Basic

With shortcuts

Props

DropdownMenu

PROPTYPEDEFAULTDESCRIPTION
openbooleanControlled open state
onOpenChange(open: boolean) => voidCalled when open state changes
modalbooleantrueWhether to render as a modal

DropdownMenuContent

PROPTYPEDEFAULTDESCRIPTION
align"start" | "center" | "end""center"Alignment relative to trigger
sidestringPreferred side of the trigger
sideOffsetnumberOffset from the trigger
loopbooleanfalseWhether keyboard navigation loops

DropdownMenuCheckboxItem

PROPTYPEDEFAULTDESCRIPTION
checkedbooleanControlled checked state
onCheckedChange(checked: boolean) => voidCalled when checked state changes

DropdownMenuRadioGroup

PROPTYPEDEFAULTDESCRIPTION
valuestringControlled selected value
onValueChange(val: string) => voidCalled when value changes

Accessibility

  • Arrow keys navigate between items
  • Enter/Space selects an item
  • Escape closes the menu
  • Type-ahead jumps to matching item