When to use
- A handful of actions on one object: a document's "⋯" menu, a row's actions, an account menu.
- View options that belong with those actions: a "Show completed" toggle, a "Sort by" choice.
- Actions that need a second level ("Move to" → projects) without leaving the menu.
When not to use
- Picking a value for a form field: use Select, which shows the value in its trigger.
- The same actions on right click: add a Context Menu as well, never instead.
- Rich content such as forms or people lists: use Popover.
- Searching hundreds of commands: use a Command palette.
Installation
pnpm dlx shadcn add https://eased.dev/r/dropdown-menu.jsonnpx shadcn add https://eased.dev/r/dropdown-menu.jsonyarn dlx shadcn add https://eased.dev/r/dropdown-menu.jsonbunx --bun shadcn add https://eased.dev/r/dropdown-menu.jsonThe command adds Dropdown Menu, everything it builds on and Eased’s tokens to your project.
Install the dependencies
pnpm add @base-ui/reactnpm install @base-ui/reactyarn add @base-ui/reactbun add @base-ui/reactAdd the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/dropdown-menu/dropdown-menu.tsxTSX "use client";import { Menu } from "@base-ui/react/menu";import { createContext, use, useEffect, useMemo, useRef, type ComponentProps, type ReactNode, type RefObject,} from "react";import { FloatingLayer, type FloatingAlign, type FloatingSide } from "../_primitives/floating/floating";import { flashThenClose, groupClass, groupLabelClass, HighlightGroup, ItemCheck, ItemChevron, itemClass, ItemParts, menuSurface, OVERLAY_ROLES, separatorClass, withHighlight,} from "../_primitives/overlay-core/overlay-core";import { Button, type ButtonSize, type ButtonVariant } from "../button/button";import { useSafeReducedMotion } from "../lib/motion";/** * A dropdown menu on Base UI's Menu. It opens on mousedown from its trigger's transform-origin, * 4px toward the trigger at 0.97 in 150ms, and leaves half as far in 100ms. One highlight glides * between rows on the snappy spring; a chosen row blinks (40ms off, 40ms on) before the menu * closes, as on macOS. Submenus open beside their row with their first row on the row's line. * * The row parts (`DropdownMenuItem` … `DropdownMenuSeparator`) also serve Context Menu: Base UI's * ContextMenu re-exports Menu's parts, so the same rows work under either root. *//* ---------------------------------------------------------- Selection flash ---------- */type Flash = { close: () => void; reduced: boolean };/** Lets a row close the whole menu after its flash. Provided by `DropdownMenu` and `ContextMenu`. */export const MenuFlashContext = createContext<Flash | null>(null);type Actions = { close: () => void; unmount: () => void };/** * The root's half of the selection flash: an actions ref for Base UI's root (yours, if you pass * one) and the context value rows read to close it. For roots that wrap Menu or ContextMenu. */export function useMenuFlash(actionsRef?: RefObject<Actions | null>) { const own = useRef<Actions | null>(null); const ref = actionsRef ?? own; const reduced = useSafeReducedMotion(); const flash = useMemo<Flash>(() => ({ close: () => ref.current?.close(), reduced }), [ref, reduced]); return { ref, flash };}/* -------------------------------------------------------------------- Root ---------- */export type DropdownMenuProps = ComponentProps<typeof Menu.Root>;/** * Groups a menu's parts and owns its open state (`open` / `defaultOpen` / `onOpenChange`). Modal by * default: page scroll locks and outside clicks only dismiss. It also lets rows flash before it * closes; `actionsRef` still reaches Base UI's `close` and `unmount`. */export function DropdownMenu({ actionsRef, children, ...props }: DropdownMenuProps) { const { ref, flash } = useMenuFlash(actionsRef); return ( <MenuFlashContext value={flash}> <Menu.Root {...props} actionsRef={ref}> {children} </Menu.Root> </MenuFlashContext> );}export type DropdownMenuTriggerProps = Omit<ComponentProps<typeof Menu.Trigger>, "className"> & { /** The Eased `Button` variant. Default "secondary"; "ghost" for a quiet "⋯" in a header. */ variant?: ButtonVariant; /** The Eased `Button` size. Default "sm" (32px); `icon-sm` for a square icon trigger. */ size?: ButtonSize; className?: string;};/** * The button that opens the menu, on mousedown (rule 71), so press-drag-release picks a row in one * gesture. An Eased `Button`: it never scales as a trigger (R64) and stays pressed * (`aria-expanded`) while the menu is open. With `openOnHover` it waits 300ms after the pointer * leaves before closing (`closeDelay`). Pass `render` for your own element (style it with `floatingTrigger`). */export function DropdownMenuTrigger({ variant = "secondary", size = "sm", className = "", render, openOnHover, closeDelay = openOnHover ? 300 : 0, ...props}: DropdownMenuTriggerProps) { return ( <Menu.Trigger {...props} openOnHover={openOnHover} closeDelay={closeDelay} render={render ?? <Button variant={variant} size={size} className={className} />} /> );}/* ----------------------------------------------------------------- Content ---------- */export type DropdownMenuContentProps = { /** Preferred side; flips on collision and the enter direction follows. Default "bottom". */ side?: FloatingSide; /** Default "start": the menu's leading edge on the trigger's. */ align?: FloatingAlign; /** Gap to the trigger, px. Default 4. */ sideOffset?: number; alignOffset?: number; /** Where focus returns on close. Default: the trigger. */ finalFocus?: ComponentProps<typeof Menu.Popup>["finalFocus"]; /** Portal target. Default `document.body`. */ container?: HTMLElement | null; /** Stacking order. Default 50; raise it inside a higher layer such as a dialog. */ zIndex?: number; /** A CSS width, e.g. `"15rem"`. Default: fits the rows, at least 192px, never wider than the viewport. */ width?: string; /** Appended to the popup's classes. */ className?: string; children?: ReactNode;};/** * The menu popup: a raised 16px panel with 4px padding whose rows share three tracks (icon · * label · trailing), so labels start on one x and shortcuts, checks and chevrons share a column. * It scrolls within the space available. */export function DropdownMenuContent({ side = OVERLAY_ROLES.menu.side, align = "start", sideOffset = OVERLAY_ROLES.menu.sideOffset, alignOffset, finalFocus, container, zIndex, width, className = "", children,}: DropdownMenuContentProps) { return ( <FloatingLayer parts={Menu} motion={OVERLAY_ROLES.menu} side={side} align={align} sideOffset={sideOffset} alignOffset={alignOffset} container={container} zIndex={zIndex} popupProps={{ finalFocus }} style={width ? { width } : undefined} className={`${menuSurface} ${className}`} > <HighlightGroup>{children}</HighlightGroup> </FloatingLayer> );}/* -------------------------------------------------------------------- Rows ---------- */type RowContent = { /** 16px icon in the leading track; muted at rest, full colour while highlighted. */ icon?: ReactNode; /** Shortcut glyphs for the trailing column, e.g. `"⌘D"`. Display only: bind the key yourself. */ shortcut?: string; /** A second, muted line under the label. */ description?: ReactNode; /** Appended to the row's classes. */ className?: string; /** The label. */ children: ReactNode;};export type DropdownMenuItemProps = Omit<ComponentProps<typeof Menu.Item>, "className" | "children" | "render"> & RowContent & { /** `"danger"`: red label and icon, a red-tinted highlight. For destructive actions. Default "default". */ tone?: "default" | "danger"; };/** * A command row. Choosing it runs `onClick`, then the row blinks for 80ms and the menu closes * (at once under reduced motion). `closeOnClick={false}` keeps the menu open and skips the blink. * `disabled` rows stay in the list and in keyboard order (so they can be read), and ignore clicks. */export function DropdownMenuItem({ icon, shortcut, description, tone = "default", closeOnClick = true, onClick, className = "", children, ...props}: DropdownMenuItemProps) { const flash = use(MenuFlashContext); const cancel = useRef<() => void>(undefined); useEffect(() => () => cancel.current?.(), []); // Without a flash-aware root (a bare Base UI Menu.Root), Base UI closes the menu itself. const flashes = flash !== null && closeOnClick; return ( <Menu.Item {...props} closeOnClick={flashes ? false : closeOnClick} onClick={(event) => { onClick?.(event); if (!flash || !flashes || event.baseUIHandlerPrevented) return; cancel.current?.(); cancel.current = flashThenClose(event.currentTarget, flash.close, flash.reduced); }} data-tone={tone === "danger" ? "danger" : undefined} className={`${itemClass({ tone, glide: true })} ${className}`} render={withHighlight} > <ItemParts icon={icon} shortcut={shortcut} description={description}> {children} </ItemParts> </Menu.Item> );}export type DropdownMenuLinkItemProps = Omit<ComponentProps<typeof Menu.LinkItem>, "className" | "children" | "render"> & RowContent;/** A row that navigates: an `<a>` with `href`. The page change is the feedback, so it doesn't blink. */export function DropdownMenuLinkItem({ icon, shortcut, description, className = "", children, ...props }: DropdownMenuLinkItemProps) { return ( <Menu.LinkItem {...props} className={`${itemClass({ glide: true })} ${className}`} render={withHighlight} > <ItemParts icon={icon} shortcut={shortcut} description={description}> {children} </ItemParts> </Menu.LinkItem> );}export type DropdownMenuCheckboxItemProps = Omit<ComponentProps<typeof Menu.CheckboxItem>, "className" | "children" | "render"> & Omit<RowContent, "icon">;/** * A toggle row (`checked` / `defaultChecked` / `onCheckedChange`). Its check sits in the icon * track and draws in when ticked. The menu stays open on click so you can set several. */export function DropdownMenuCheckboxItem({ shortcut, description, className = "", children, ...props }: DropdownMenuCheckboxItemProps) { return ( <Menu.CheckboxItem {...props} className={`${itemClass({ glide: true })} ${className}`} render={withHighlight}> <ItemParts icon={ <Menu.CheckboxItemIndicator keepMounted className="flex"> <ItemCheck /> </Menu.CheckboxItemIndicator> } shortcut={shortcut} description={description} > {children} </ItemParts> </Menu.CheckboxItem> );}export type DropdownMenuRadioGroupProps = Omit<ComponentProps<typeof Menu.RadioGroup>, "className"> & { className?: string };/** One choice among its `DropdownMenuRadioItem`s (`value` / `defaultValue` / `onValueChange`). Keeps the rows on the menu's tracks. */export function DropdownMenuRadioGroup({ className = "", ...props }: DropdownMenuRadioGroupProps) { return <Menu.RadioGroup {...props} className={`${groupClass} ${className}`} />;}export type DropdownMenuRadioItemProps = Omit<ComponentProps<typeof Menu.RadioItem>, "className" | "children" | "render"> & Omit<RowContent, "icon">;/** One option of a radio group (`value` required). The check marks the chosen one; the menu stays open on click. */export function DropdownMenuRadioItem({ shortcut, description, className = "", children, ...props }: DropdownMenuRadioItemProps) { return ( <Menu.RadioItem {...props} className={`${itemClass({ glide: true })} ${className}`} render={withHighlight}> <ItemParts icon={ <Menu.RadioItemIndicator keepMounted className="flex"> <ItemCheck /> </Menu.RadioItemIndicator> } shortcut={shortcut} description={description} > {children} </ItemParts> </Menu.RadioItem> );}/* ---------------------------------------------------------------- Submenus ---------- *//** A nested menu: holds one `DropdownMenuSubTrigger` and one `DropdownMenuSubContent`. Base UI `Menu.SubmenuRoot`. */export const DropdownMenuSub = Menu.SubmenuRoot;export type DropdownMenuSubTriggerProps = Omit<ComponentProps<typeof Menu.SubmenuTrigger>, "className" | "children" | "render"> & Omit<RowContent, "shortcut">;/** * The row that opens a submenu: a chevron in the trailing column. It opens on hover (100ms * `delay`), click, Enter or ArrowRight; Base UI's safe-hover triangle keeps it open while the * pointer travels diagonally to it. While the submenu is open the row keeps a quiet fill. */export function DropdownMenuSubTrigger({ icon, description, className = "", children, ...props }: DropdownMenuSubTriggerProps) { return ( <Menu.SubmenuTrigger {...props} className={`${itemClass({ glide: true })} data-popup-open:bg-surface-hover ${className}`} render={withHighlight} > <ItemParts icon={icon} description={description} trailing={<ItemChevron />}> {children} </ItemParts> </Menu.SubmenuTrigger> );}/** The menu's 1px border plus its 4px padding: how far a submenu rises so its first row sits on its trigger row. */const SUBMENU_ALIGN_OFFSET = -5;export type DropdownMenuSubContentProps = Pick<DropdownMenuContentProps, "container" | "zIndex" | "width" | "className" | "children">;/** * The submenu popup, beside its row (flipping to the other side on collision), raised by the * menu's border and padding so its first row lines up with the trigger row. It slides 4px out * from the parent and has its own gliding highlight. */export function DropdownMenuSubContent({ container, zIndex, width, className = "", children }: DropdownMenuSubContentProps) { return ( <FloatingLayer parts={Menu} motion={OVERLAY_ROLES.submenu} side={OVERLAY_ROLES.submenu.side} align="start" sideOffset={OVERLAY_ROLES.submenu.sideOffset} alignOffset={SUBMENU_ALIGN_OFFSET} container={container} zIndex={zIndex} style={width ? { width } : undefined} className={`${menuSurface} ${className}`} > <HighlightGroup>{children}</HighlightGroup> </FloatingLayer> );}/* ---------------------------------------------------------------- Grouping ---------- */export type DropdownMenuGroupProps = Omit<ComponentProps<typeof Menu.Group>, "className"> & { className?: string };/** Related rows, labelled by a `DropdownMenuLabel` inside it. Keeps its rows on the menu's tracks. */export function DropdownMenuGroup({ className = "", ...props }: DropdownMenuGroupProps) { return <Menu.Group {...props} className={`${groupClass} ${className}`} />;}export type DropdownMenuLabelProps = Omit<ComponentProps<typeof Menu.GroupLabel>, "className"> & { className?: string };/** A group's heading: 12px, muted, 28px tall. Names its `DropdownMenuGroup` or `DropdownMenuRadioGroup`. */export function DropdownMenuLabel({ className = "", ...props }: DropdownMenuLabelProps) { return <Menu.GroupLabel {...props} className={`${groupLabelClass} ${className}`} />;}/** A full-bleed 1px rule between groups. */export function DropdownMenuSeparator({ className = "" }: { className?: string }) { return <Menu.Separator className={`${separatorClass} ${className}`} />;}Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger,} from "@/components/eased/dropdown-menu/dropdown-menu";export function DocumentMenu() { return ( <DropdownMenu> <DropdownMenuTrigger variant="ghost" size="icon-sm" aria-label="Document options"> <MoreIcon /> </DropdownMenuTrigger> <DropdownMenuContent align="end"> <DropdownMenuItem icon={<DuplicateIcon />} shortcut="⌘D" onClick={duplicate}> Duplicate </DropdownMenuItem> <DropdownMenuItem icon={<LinkIcon />} onClick={copyLink}> Copy link </DropdownMenuItem> <DropdownMenuSeparator /> <DropdownMenuItem icon={<TrashIcon />} shortcut="⌘⌫" tone="danger" onClick={trash}> Delete </DropdownMenuItem> </DropdownMenuContent> </DropdownMenu> );}Examples
Checkbox and radio rows
Toggles and one-of-many choices stay open on click so people can set several; the check draws into the icon track.
<DropdownMenuCheckboxItem checked={showCompleted} onCheckedChange={setShowCompleted}> Show completed</DropdownMenuCheckboxItem><DropdownMenuSeparator /><DropdownMenuRadioGroup value={sort} onValueChange={setSort}> <DropdownMenuLabel>Sort by</DropdownMenuLabel> <DropdownMenuRadioItem value="updated">Last updated</DropdownMenuRadioItem> <DropdownMenuRadioItem value="created">Date created</DropdownMenuRadioItem> <DropdownMenuRadioItem value="name">Name</DropdownMenuRadioItem></DropdownMenuRadioGroup>Submenu
The submenu opens beside its row, with its first row on the trigger row's line.
<DropdownMenuSub> <DropdownMenuSubTrigger icon={<FolderIcon />}>Move to</DropdownMenuSubTrigger> <DropdownMenuSubContent> {projects.map((p) => ( <DropdownMenuItem key={p.id} disabled={p.id === current} onClick={() => move(p.id)}> {p.name} </DropdownMenuItem> ))} </DropdownMenuSubContent></DropdownMenuSub>A disabled row that says why
Keep unavailable commands in place and say why on the row (rule 67), not in a tooltip.
<DropdownMenuItem icon={<DownloadIcon />} description="On the Team plan" disabled> Export as PDF</DropdownMenuItem>API reference
DropdownMenu
Base UI Menu.Root: open, defaultOpen, onOpenChange, modal (true), loopFocus, closeParentOnEsc, actionsRef and the rest. It also provides the context rows use to blink before closing; your actionsRef still receives Base UI's close and unmount.
DropdownMenuTrigger
Base UI Menu.Trigger props, rendered as an Eased Button.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | ButtonVariant | "secondary" | The Button variant; "ghost" for a quiet header "⋯". |
size | ButtonSize | "sm" | "icon-sm" for a square icon trigger. |
openOnHover | boolean | Also open on hover (100ms delay). | |
closeDelay | number | 300 with openOnHover, else 0 | Wait after the pointer leaves before closing (rule 71). |
render | ReactElement | function | Your own trigger; style it with floatingTrigger. | |
className | string | "" | Appended to the Button's classes. |
DropdownMenuContent
| Prop | Type | Default | Description |
|---|---|---|---|
side | FloatingSide | "bottom" | Flips on collision; the enter direction follows. |
align | "start" | "center" | "end" | "start" | |
sideOffset | number | 4 | Gap to the trigger, px. |
alignOffset | number | 0 | |
finalFocus | Base UI finalFocus | the trigger | Where focus goes on close. |
container | HTMLElement | null | document.body | Portal target. |
zIndex | number | 50 | Raise it inside a dialog. |
width | string | fits the rows, ≥ 192px | A CSS width, e.g. "15rem". Never wider than the viewport. |
className | string | "" | Appended to the popup's classes. |
DropdownMenuItem
Base UI Menu.Item props (onClick, disabled, label, …), plus:
| Prop | Type | Default | Description |
|---|---|---|---|
icon | ReactNode | 16px icon in the leading track. | |
shortcut | string | Glyphs for the trailing column, e.g. "⌘⇧C". Display only; bind the key yourself. | |
description | ReactNode | A second, muted line. | |
tone | "default" | "danger" | "default" | "danger" for destructive actions: red label, red-tinted highlight. |
closeOnClick | boolean | true | false keeps the menu open and skips the blink. |
DropdownMenuLinkItem takes the same content props on Base UI Menu.LinkItem (href); it doesn't blink, because the navigation is the feedback.
DropdownMenuCheckboxItem, DropdownMenuRadioGroup, DropdownMenuRadioItem
Base UI Menu.CheckboxItem (checked, defaultChecked, onCheckedChange), Menu.RadioGroup (value, defaultValue, onValueChange) and Menu.RadioItem (value), with shortcut and description. The check takes the icon track.
DropdownMenuSub, DropdownMenuSubTrigger, DropdownMenuSubContent
DropdownMenuSub is Base UI Menu.SubmenuRoot. DropdownMenuSubTrigger takes icon and description plus Base UI's openOnHover (true), delay (100) and closeDelay (0). DropdownMenuSubContent takes width, container, zIndex and className.
DropdownMenuGroup, DropdownMenuLabel, DropdownMenuSeparator
A group of rows on the menu's tracks, its 12px muted heading, and a full-bleed 1px rule.
useMenuFlash, MenuFlashContext
For building another root (Context Menu does): useMenuFlash(actionsRef?) returns { ref, flash }; pass ref as Base UI's actionsRef and provide flash through MenuFlashContext.
Keyboard
| Key | Action |
|---|---|
Enter / Space / ArrowDown on the trigger | Opens the menu and highlights the first row. |
ArrowUp / ArrowDown | Moves the highlight; loops at the ends. |
Home / End | First or last row. |
| A letter | Jumps to the next row starting with it. |
Enter / Space | Chooses the row (toggles a checkbox or radio row). |
ArrowRight / ArrowLeft | Opens a submenu / closes it and returns to its row. |
Escape | Closes the current menu; focus returns to the trigger. |
Accessibility
- The trigger is a
buttonwitharia-haspopup="menu"andaria-expanded; give an icon-only trigger anaria-label. - The popup is a
menu; rows aremenuitem,menuitemcheckboxandmenuitemradio, witharia-checkedandaria-disabled. Group labels name their groups. - Shortcuts are read by name ("Command Shift C"); icons and checks are hidden from assistive tech.
- Focus moves into the menu on open and back to the trigger on close (
finalFocusto send it elsewhere, e.g. a rename field). - Rows are 32px, 40px on coarse pointers. Disabled rows stay in arrow-key order so they can be read (Base UI), dimmed, and ignore clicks.
Motion
The menu opens on mousedown from the trigger's transform-origin: 4px toward the trigger at 0.97, transform on the snappy spring, opacity over 150ms; it leaves half as far and scales half as much in 100ms on the standard curve, with no overshoot. Both are CSS transitions on Base UI's data-starting-style / data-ending-style, so a quick open-close reverses mid-flight. One highlight glides between rows on the snappy spring (each submenu has its own); rows never scale or change weight. Choosing a command blinks its highlight off for 40ms and on for 40ms, then the menu closes, as macOS does; checkbox and radio rows don't blink. A submenu slides 4px out from its row. Under reduced motion the menu only fades (100ms), the highlight jumps, and choosing closes at once.
Notes for AI
Use DropdownMenu for commands on an object; put the trigger in the object's header as a ghost size="icon-sm" button with an aria-label, and align="end" the content when the trigger sits on the right edge. Give destructive rows tone="danger" and follow them with an undo or confirm step (rule 73). Use description on a disabled row to say why it is unavailable.
Don't wrap rows in your own buttons or add onKeyDown navigation: Base UI handles focus, typeahead and dismissal. Don't call setOpen(false) in an item's onClick; the row closes the menu itself after its blink. Shortcuts are labels only; register the key bindings in your app.
Related components
- Right-Click Context Menu: the same rows, opened at the pointer by right click or long press.
- Animated Popover: an anchored panel for content rather than commands.
- Cmd+K Command Palette