bearnie

Dropdown Menu

Menu of actions triggered by a button.

Installation

npx bearnie add dropdown-menu
npx bearnie add dropdown-menu

Usage

import {
  DropdownMenu,
  DropdownMenuTrigger,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuSeparator,
} from "@/components/bearnie/dropdown-menu"
<DropdownMenu>
  <DropdownMenuTrigger>
    <Button>Open</Button>
  </DropdownMenuTrigger>
  <DropdownMenuContent>
    <DropdownMenuItem>Item 1</DropdownMenuItem>
    <DropdownMenuItem>Item 2</DropdownMenuItem>
  </DropdownMenuContent>
</DropdownMenu>

Examples

Align start

Align center

Align end

With icons

Icon button trigger

Nest DropdownMenuSub inside the content to open a second-level menu on hover, click, or ArrowRight. ArrowLeft or Escape returns to the parent menu.

Checkbox and radio items

Checkbox and radio items keep the menu open so several can be toggled in one visit. They emit dropdown-checkbox-change and dropdown-radio-change custom events (both bubble) when the selection changes.

Anatomy

  • DropdownMenu - The root container
  • DropdownMenuTrigger - The element that opens the menu
  • DropdownMenuContent - The dropdown panel
  • DropdownMenuItem - Individual menu items
  • DropdownMenuLabel - Non-interactive label text
  • DropdownMenuSeparator - Visual divider between items
  • DropdownMenuSub - Wraps a submenu trigger and its content
  • DropdownMenuSubTrigger - Item that opens the submenu
  • DropdownMenuSubContent - The nested submenu panel
  • DropdownMenuCheckboxItem - Toggleable item with a check indicator
  • DropdownMenuRadioGroup - Groups radio items with a single selection
  • DropdownMenuRadioItem - Selectable item within a radio group

Props

Prop Type Default Description
align start | center | end end Horizontal alignment
class string - Additional CSS classes
Prop Type Default Description
href string - Renders the item as a link instead of a button
disabled boolean false Disables the item
destructive boolean false Destructive styling
class string - Additional CSS classes
Prop Type Default Description
disabled boolean false Disables the submenu trigger
inset boolean false Indents the trigger to align with checkbox/radio items
class string - Additional CSS classes
Prop Type Default Description
checked boolean false Initial checked state
disabled boolean false Disables the item
class string - Additional CSS classes
Prop Type Default Description
defaultValue string - Initially selected value
class string - Additional CSS classes
Prop Type Default Description
value string - The value this item represents (required)
disabled boolean false Disables the item
class string - Additional CSS classes

All other DropdownMenu components accept class for additional CSS classes.

Events

Event Target Detail Description
dropdown-checkbox-change DropdownMenuCheckboxItem { checked: boolean } Fired when a checkbox item is toggled
dropdown-radio-change DropdownMenuRadioGroup { value: string } Fired when the radio selection changes

Both events bubble, so a single listener on the menu (or document) can observe every change.