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

Switch items

DropdownMenuSwitchItem is for a setting the menu TOGGLES and keeps showing; DropdownMenuCheckboxItem is for a choice the menu RECORDS and dismisses. That is why this one does not close on click: a switch that flips and then vanishes gives you no chance to see the state you just set. The Switch is decorative markup, so the row keeps one accessible name and one hit target.

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""center"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.