Dropdown Menu for Astro
Astro action menus with item, checkbox, and radio compositions.
Installation
bunx --bun shadcn@latest add @gnostic/dropdown-menunpx shadcn@latest add @gnostic/dropdown-menupnpm dlx shadcn@latest add @gnostic/dropdown-menuInstall component packages
bun add @data-slot/dropdown-menunpm install @data-slot/dropdown-menupnpm add @data-slot/dropdown-menuCopy the files
src/components/ui/dropdown-menu/dropdown-menu-checkbox-item.astrosrc/components/ui/dropdown-menu/dropdown-menu-content.astrosrc/components/ui/dropdown-menu/dropdown-menu-group.astrosrc/components/ui/dropdown-menu/dropdown-menu-item.astrosrc/components/ui/dropdown-menu/dropdown-menu-label.astrosrc/components/ui/dropdown-menu/dropdown-menu-portal.astrosrc/components/ui/dropdown-menu/dropdown-menu-radio-item.astrosrc/components/ui/dropdown-menu/dropdown-menu-separator.astrosrc/components/ui/dropdown-menu/dropdown-menu-shortcut.astrosrc/components/ui/dropdown-menu/dropdown-menu-trigger.astrosrc/components/ui/dropdown-menu/dropdown-menu.astrosrc/components/ui/dropdown-menu/index.tssrc/components/ui/dropdown-menu/types.ts
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
DropdownMenuProps
defaultOpen?boolean
Initial open state
booleandefaultValue?string | null
Initial radio selection state
string | nulldefaultValues?string[]
Initial checkbox selection state
string[]closeOnClickOutside?boolean
Close when clicking outside
booleancloseOnEscape?boolean
Close when pressing Escape
booleancloseOnSelect?boolean
Close when an item is selected
booleanhighlightItemOnHover?boolean
Whether moving the pointer over items should highlight and focus them.
booleantrueside?Side
The preferred side of the trigger to render against. Will be reversed when collisions occur and `avoidCollisions` is enabled.
Side"bottom"align?Align
The preferred alignment against the trigger. May change when collisions occur.
Align"start"sideOffset?number
The distance in pixels from the trigger.
number4alignOffset?number
An offset in pixels from the "start" or "end" alignment options.
number0avoidCollisions?boolean
When true, overrides side/align preferences to prevent collisions with viewport edges.
booleantruecollisionPadding?number
The padding between the content and the viewport edges when avoiding collisions.
number8lockScroll?boolean
Lock body scroll when open.
booleantrueDropdownMenuContentProps
side?Side
The preferred side of the trigger to render against. Will be reversed when collisions occur and `avoidCollisions` is enabled.
Side"bottom"align?Align
The preferred alignment against the trigger. May change when collisions occur.
Align"start"sideOffset?number
The distance in pixels from the trigger.
number4alignOffset?number
An offset in pixels from the "start" or "end" alignment options.
number0avoidCollisions?boolean
When true, overrides side/align preferences to prevent collisions with viewport edges.
booleantruecollisionPadding?number
The padding between the content and the viewport edges when avoiding collisions.
number8See 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.