UI.MD

Dropdown Menu

A menu of actions triggered by a button. Supports items, labels, separators, and sub-menus.

Installation

$
npx shadcn@latest add https://ui.mattdowney.com/r/dropdown-menu.json

Usage

import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator } from "@/components/ui/dropdown-menu"

Examples

Default

A list of actions off a button. The trigger takes your own element through render, and variant="destructive" tints the one item people should slow down on.

Switch items

DropdownMenuSwitchItem is for a setting the menu toggles and keeps showing, so it does not close on click; DropdownMenuCheckboxItem is for a choice the menu records and then dismisses. The switch is decorative, so the row keeps one name and one hit target. Not for theme unless the app has no system.

Radio filter

DropdownMenuRadioGroup turns the menu into a single-select filter, triggered by a Kebab. The checked item is marked by a checkmark, matching the Select selection language; hover and keyboard focus take the solid bg-accent highlight.

Positioning

Control where the menu opens with side (top/right/bottom/left) and align (start/center/end) on DropdownMenuContent; both pass straight through to Base UI's positioner. Pick a cell and the code below updates to match your selection.

Menu placement

side="bottom" align="start"

API Reference

PropTypeDefaultDescription
sideDropdownMenuContent"top" | "right" | "bottom" | "left""bottom"Preferred edge of the trigger to render against.
alignDropdownMenuContent"start" | "center" | "end""start"Alignment against the trigger along the chosen side.
sideOffsetDropdownMenuContentnumber4Distance in pixels between the menu and the trigger.
avoidCollisionsDropdownMenuContentbooleantrueWhen true, flips/shifts the menu to stay in view. Set false to always honor side.
variantDropdownMenuItem"default" | "destructive""default"Visual intent of a menu item; destructive tints the item and its icon red.
insetDropdownMenuItem, DropdownMenuLabel, DropdownMenuSubTriggerboolean-Adds left padding so the item aligns with checkbox/radio items.
checkedDropdownMenuCheckboxItem, DropdownMenuSwitchItemboolean | "indeterminate"-Controlled checked state, paired with onCheckedChange.
renderDropdownMenuTriggerReact.ReactElement-Replaces the default trigger button with your own element, e.g. render={<Button>Open</Button>}. Base UI merges props onto it.