Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Dropdown Menu for Astro

Astro action menus with item, checkbox, and radio compositions.

API Reference

Installation

bunx --bun shadcn@latest add @gnostic/dropdown-menu

Usage

---
import ChevronDownIcon from "@lucide/astro/icons/chevron-down"

import { buttonVariants } from "@/components/ui/button"
import {
  DropdownMenu,
  DropdownMenuCheckboxItem,
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuRadioItem,
  DropdownMenuSeparator,
  DropdownMenuShortcut,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
---
<DropdownMenu>
  <DropdownMenuTrigger class={buttonVariants({ variant: "outline" })}>
    Open
    <ChevronDownIcon class="size-4 opacity-60" />
  </DropdownMenuTrigger>
  <DropdownMenuContent class="w-56">
    <DropdownMenuGroup>
      <DropdownMenuLabel>My Account</DropdownMenuLabel>
      <DropdownMenuItem>Profile</DropdownMenuItem>
      <DropdownMenuItem>Billing</DropdownMenuItem>
    </DropdownMenuGroup>
    <DropdownMenuSeparator />
    <DropdownMenuGroup>
      <DropdownMenuCheckboxItem value="email">
        Email notifications
      </DropdownMenuCheckboxItem>
      <DropdownMenuRadioItem value="pro">Pro plan</DropdownMenuRadioItem>
    </DropdownMenuGroup>
  </DropdownMenuContent>
</DropdownMenu>

Composition

Arrange the parts as shown for a DropdownMenu:

DropdownMenu
├── DropdownMenuTrigger
└── DropdownMenuContent
    ├── DropdownMenuGroup
    │   ├── DropdownMenuLabel
    │   ├── DropdownMenuItem
    │   └── DropdownMenuItem
    ├── DropdownMenuSeparator
    └── DropdownMenuGroup
        ├── DropdownMenuCheckboxItem
        ├── DropdownMenuRadioItem
        └── DropdownMenuItem
            └── DropdownMenuShortcut

Examples

Basic

A basic dropdown menu with labels and separators.

With Shortcuts

Add DropdownMenuShortcut to show keyboard hints.

With Icons

Combine icons with labels for quick scanning.

With Checkboxes

Use DropdownMenuCheckboxItem for toggles. Set closeOnSelect={false} when multiple selections should stay in the menu.

With Radio Group

Use DropdownMenuRadioItem for exclusive choices. The current selection is stored on the root DropdownMenu through defaultValue.

With Destructive Items

Use variant="destructive" for irreversible actions.

With Avatar

An account dropdown triggered by a compact profile button.

Sides

Use side, align, and sideOffset on DropdownMenuContent to control the popup placement without exposing the lower-level positioning wrappers.

API Reference

PropType
defaultOpen?boolean

Initial open state

Typeboolean
defaultValue?string | null

Initial radio selection state

Typestring | null
defaultValues?string[]

Initial checkbox selection state

Typestring[]
closeOnClickOutside?boolean

Close when clicking outside

Typeboolean
closeOnEscape?boolean

Close when pressing Escape

Typeboolean
closeOnSelect?boolean

Close when an item is selected

Typeboolean
highlightItemOnHover?boolean

Whether moving the pointer over items should highlight and focus them.

Typeboolean
Defaulttrue
side?Side

The preferred side of the trigger to render against. Will be reversed when collisions occur and `avoidCollisions` is enabled.

TypeSide
Default"bottom"
align?Align

The preferred alignment against the trigger. May change when collisions occur.

TypeAlign
Default"start"
sideOffset?number

The distance in pixels from the trigger.

Typenumber
Default4
alignOffset?number

An offset in pixels from the "start" or "end" alignment options.

Typenumber
Default0
avoidCollisions?boolean

When true, overrides side/align preferences to prevent collisions with viewport edges.

Typeboolean
Defaulttrue
collisionPadding?number

The padding between the content and the viewport edges when avoiding collisions.

Typenumber
Default8
lockScroll?boolean

Lock body scroll when open.

Typeboolean
Defaulttrue
PropType
side?Side

The preferred side of the trigger to render against. Will be reversed when collisions occur and `avoidCollisions` is enabled.

TypeSide
Default"bottom"
align?Align

The preferred alignment against the trigger. May change when collisions occur.

TypeAlign
Default"start"
sideOffset?number

The distance in pixels from the trigger.

Typenumber
Default4
alignOffset?number

An offset in pixels from the "start" or "end" alignment options.

Typenumber
Default0
avoidCollisions?boolean

When true, overrides side/align preferences to prevent collisions with viewport edges.

Typeboolean
Defaulttrue
collisionPadding?number

The padding between the content and the viewport edges when avoiding collisions.

Typenumber
Default8

See the data-slot docs for more information on interactivity.

Events

Dispatch these events on the dropdown menu root. The root emits the outbound events.

Outbound events

Event Detail
dropdown-menu:open-change { open: boolean, previousOpen: boolean, source: "pointer" | "keyboard" | "programmatic" | "restore" | "init", reason: "trigger" | "select" | "outside" | "escape" | "tab" | "programmatic" | "init" }
dropdown-menu:change same detail as dropdown-menu:open-change
dropdown-menu:highlight-change { value: string | null, previousValue: string | null, item: HTMLElement | null, previousItem: HTMLElement | null, source: "pointer" | "keyboard" | "programmatic" | "restore" }
dropdown-menu:select { value: string, item: HTMLElement, itemType: "item" | "radio" | "checkbox", source: "pointer" | "keyboard", checked?: boolean }
dropdown-menu:value-change { value: string | null, previousValue: string | null, item: HTMLElement | null, previousItem: HTMLElement | null, source: "pointer" | "keyboard" | "programmatic" | "restore" }
dropdown-menu:values-change { values: string[], previousValues: string[], changedValue: string | null, checked: boolean | null, item: HTMLElement | null, source: "pointer" | "keyboard" | "programmatic" | "restore" }

dropdown-menu:select is cancelable. Call event.preventDefault() to stop the selection. dropdown-menu:change is a deprecated alias of dropdown-menu:open-change.

Inbound events

Event Detail
dropdown-menu:set { open?: boolean, value?: string | null, values?: string[], highlightedValue?: string | null, source?: "programmatic" | "restore" }

Read the installed source for the complete prop types.

When to use Dropdown Menu

Put a DropdownMenuTrigger and content under one menu root. Use menu items for actions, checkbox items for independent settings, and radio groups for one selection. Keep action labels short and specific.

Keyboard and behavior

The data-slot menu controller manages opening and item navigation. Test arrow keys, activation, Escape, and focus return. This port has no public submenu parts; a similar-looking nested list is not a supported submenu.

Theme and layout

Item padding, separators, and popup shadows use the shared style system. A long menu can scroll. Keep destructive wording explicit and check disabled items in both modes.