Dropdown Menu
A list of actions behind a button. Use it for row and page actions, bulk actions on a narrow toolbar, filters, and account menus. Arrow keys move through items, and focus returns to the trigger when it closes.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/dropdown-menu.jsonCopies Dropdown Menu into your app, installs the packages, and adds the styles. Then import it from @/components/ui/dropdown-menu. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-merge @base-ui/react @hugeicons/core-free-icons @hugeicons/reactAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Copy and paste the following code into your project.
'use client'; import type { ComponentProps } from 'react'; import { Menu as MenuPrimitive } from '@base-ui/react/menu'; import { CheckIcon } from '@/lib/sprout/icons/check-icon'; import { ChevronRightIcon } from '@/lib/sprout/icons/chevron-right-icon'; import { cn, stateClassName } from '@/lib/sprout/classes'; export const dropdownMenuContentSizeNames = ['anchor', 'menu'] as const; export const dropdownMenuItemVariantNames = ['default', 'destructive'] as const; export type DropdownMenuContentSize = (typeof dropdownMenuContentSizeNames)[number]; export type DropdownMenuItemVariant = (typeof dropdownMenuItemVariantNames)[number]; export type DropdownMenuProps = MenuPrimitive.Root.Props; export function DropdownMenu(props: DropdownMenuProps) { return <MenuPrimitive.Root {...props} />; } export type DropdownMenuPortalProps = MenuPrimitive.Portal.Props; export function DropdownMenuPortal(props: DropdownMenuPortalProps) { return <MenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />; } export type DropdownMenuTriggerProps = MenuPrimitive.Trigger.Props; export function DropdownMenuTrigger(props: DropdownMenuTriggerProps) { return <MenuPrimitive.Trigger data-slot="dropdown-menu-trigger" {...props} />; } type PositionerProps = Pick< MenuPrimitive.Positioner.Props, | 'align' | 'alignOffset' | 'side' | 'sideOffset' | 'collisionPadding' | 'collisionAvoidance' | 'sticky' | 'positionMethod' >; export interface DropdownMenuContentProps extends MenuPrimitive.Popup.Props, PositionerProps { size?: DropdownMenuContentSize; container?: MenuPrimitive.Portal.Props['container']; } export function DropdownMenuContent({ align = 'start', alignOffset = 0, side = 'bottom', sideOffset = 4, collisionPadding = 8, collisionAvoidance, sticky, positionMethod, size = 'anchor', container, className, ...props }: DropdownMenuContentProps) { return ( <MenuPrimitive.Portal container={container}> <MenuPrimitive.Positioner className="sprout-dropdown-menu-positioner" align={align} alignOffset={alignOffset} side={side} sideOffset={sideOffset} collisionPadding={collisionPadding} collisionAvoidance={collisionAvoidance} sticky={sticky} positionMethod={positionMethod} > <MenuPrimitive.Popup data-slot="dropdown-menu-content" data-size={size} {...props} className={stateClassName<MenuPrimitive.Popup.State>( cn('sprout-dropdown-menu-content', `sprout-dropdown-menu-${size}`), className, )} /> </MenuPrimitive.Positioner> </MenuPrimitive.Portal> ); } export type DropdownMenuGroupProps = MenuPrimitive.Group.Props; export function DropdownMenuGroup(props: DropdownMenuGroupProps) { return <MenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />; } interface Inset { inset?: boolean; } export interface DropdownMenuLabelProps extends MenuPrimitive.GroupLabel.Props, Inset {} export function DropdownMenuLabel({ className, inset, ...props }: DropdownMenuLabelProps) { return ( <MenuPrimitive.GroupLabel data-slot="dropdown-menu-label" data-inset={inset || undefined} {...props} className={stateClassName<MenuPrimitive.GroupLabel.State>('sprout-dropdown-menu-label', className)} /> ); } export interface DropdownMenuItemProps extends MenuPrimitive.Item.Props, Inset { variant?: DropdownMenuItemVariant; } export function DropdownMenuItem({ className, inset, variant = 'default', ...props }: DropdownMenuItemProps) { return ( <MenuPrimitive.Item data-slot="dropdown-menu-item" data-inset={inset || undefined} data-variant={variant} {...props} className={stateClassName<MenuPrimitive.Item.State>('sprout-dropdown-menu-item', className)} /> ); } export type DropdownMenuSubProps = MenuPrimitive.SubmenuRoot.Props; export function DropdownMenuSub(props: DropdownMenuSubProps) { return <MenuPrimitive.SubmenuRoot {...props} />; } export interface DropdownMenuSubTriggerProps extends MenuPrimitive.SubmenuTrigger.Props, Inset {} export function DropdownMenuSubTrigger({ className, inset, children, ...props }: DropdownMenuSubTriggerProps) { return ( <MenuPrimitive.SubmenuTrigger data-slot="dropdown-menu-sub-trigger" data-inset={inset || undefined} {...props} className={stateClassName<MenuPrimitive.SubmenuTrigger.State>( 'sprout-dropdown-menu-item sprout-dropdown-menu-sub-trigger', className, )} > {children} <ChevronRightIcon size="md" aria-hidden="true" className="sprout-dropdown-menu-sub-chevron" /> </MenuPrimitive.SubmenuTrigger> ); } export type DropdownMenuSubContentProps = DropdownMenuContentProps; export function DropdownMenuSubContent({ align = 'start', alignOffset = -5, side = 'right', sideOffset = 0, className, ...props }: DropdownMenuSubContentProps) { return ( <DropdownMenuContent data-slot="dropdown-menu-sub-content" align={align} alignOffset={alignOffset} side={side} sideOffset={sideOffset} {...props} className={stateClassName<MenuPrimitive.Popup.State>('sprout-dropdown-menu-sub-content', className)} /> ); } export interface DropdownMenuCheckboxItemProps extends MenuPrimitive.CheckboxItem.Props, Inset {} export function DropdownMenuCheckboxItem({ className, inset, children, ...props }: DropdownMenuCheckboxItemProps) { return ( <MenuPrimitive.CheckboxItem data-slot="dropdown-menu-checkbox-item" data-inset={inset || undefined} {...props} className={stateClassName<MenuPrimitive.CheckboxItem.State>( 'sprout-dropdown-menu-item sprout-dropdown-menu-choice', className, )} > <span className="sprout-dropdown-menu-indicator" data-slot="dropdown-menu-checkbox-item-indicator"> <MenuPrimitive.CheckboxItemIndicator> <CheckIcon size="md" aria-hidden="true" /> </MenuPrimitive.CheckboxItemIndicator> </span> {children} </MenuPrimitive.CheckboxItem> ); } export type DropdownMenuRadioGroupProps = MenuPrimitive.RadioGroup.Props; export function DropdownMenuRadioGroup(props: DropdownMenuRadioGroupProps) { return <MenuPrimitive.RadioGroup data-slot="dropdown-menu-radio-group" {...props} />; } export interface DropdownMenuRadioItemProps extends MenuPrimitive.RadioItem.Props, Inset {} export function DropdownMenuRadioItem({ className, inset, children, ...props }: DropdownMenuRadioItemProps) { return ( <MenuPrimitive.RadioItem data-slot="dropdown-menu-radio-item" data-inset={inset || undefined} {...props} className={stateClassName<MenuPrimitive.RadioItem.State>( 'sprout-dropdown-menu-item sprout-dropdown-menu-choice', className, )} > <span className="sprout-dropdown-menu-indicator" data-slot="dropdown-menu-radio-item-indicator"> <MenuPrimitive.RadioItemIndicator> <CheckIcon size="md" aria-hidden="true" /> </MenuPrimitive.RadioItemIndicator> </span> {children} </MenuPrimitive.RadioItem> ); } export type DropdownMenuSeparatorProps = MenuPrimitive.Separator.Props; export function DropdownMenuSeparator({ className, ...props }: DropdownMenuSeparatorProps) { return ( <MenuPrimitive.Separator data-slot="dropdown-menu-separator" {...props} className={stateClassName<MenuPrimitive.Separator.State>('sprout-dropdown-menu-separator', className)} /> ); } export type DropdownMenuShortcutProps = ComponentProps<'span'>; export function DropdownMenuShortcut({ className, ...props }: DropdownMenuShortcutProps) { return ( <span data-slot="dropdown-menu-shortcut" {...props} className={cn('sprout-dropdown-menu-shortcut', className)} /> ); }And the files it imports:
lib/sprout/icons/check-icon.tsxlib/sprout/icons/chevron-right-icon.tsxlib/sprout/icons/create-icon.tsx
Add the styles to your global CSS, after
@import "tailwindcss".@layer components { .sprout-dropdown-menu-positioner { z-index: 50; isolation: isolate; outline: none; } .sprout-dropdown-menu-content { box-sizing: border-box; min-width: 8rem; max-width: var(--available-width); max-height: var(--available-height); overscroll-behavior: contain; border: 1px solid var(--sprout-line); border-radius: var(--sprout-radius-panel); background: var(--sprout-popover); color: var(--sprout-text); box-shadow: var(--sprout-shadow-overlay); font-family: var(--sprout-font); font-size: var(--sprout-text-sm); scrollbar-width: thin; transform-origin: var(--transform-origin); outline: none; padding: 4px; line-height: 1.25rem; overflow: hidden auto; } .sprout-dropdown-menu-anchor { width: var(--anchor-width); } .sprout-dropdown-menu-menu { width: 16rem; } .sprout-dropdown-menu-content.sprout-dropdown-menu-sub-content { width: auto; min-width: 6rem; } .sprout-dropdown-menu-label { color: var(--sprout-muted); font-size: var(--sprout-text-xs); overflow-wrap: break-word; padding: 4px 6px; font-weight: 500; line-height: 1rem; } .sprout-dropdown-menu-item { box-sizing: border-box; min-width: 0; min-height: calc(var(--sprout-control-height) - 4px); border-radius: var(--sprout-radius-control); color: var(--sprout-text); font: inherit; text-align: start; overflow-wrap: break-word; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; outline: none; align-items: center; gap: 6px; padding: 4px 6px; text-decoration: none; display: flex; position: relative; } .sprout-dropdown-menu-item :where(svg) { pointer-events: none; flex-shrink: 0; width: 16px; height: 16px; } .sprout-dropdown-menu-item[data-highlighted], .sprout-dropdown-menu-sub-trigger[data-popup-open] { background: var(--sprout-hover); color: var(--sprout-text); } .sprout-dropdown-menu-item[data-variant="destructive"] { color: var(--sprout-danger); } .sprout-dropdown-menu-item[data-variant="destructive"][data-highlighted] { background: var(--sprout-danger-subtle); color: var(--sprout-danger); } .sprout-dropdown-menu-item[data-disabled] { opacity: .5; cursor: default; pointer-events: none; } :is(.sprout-dropdown-menu-item, .sprout-dropdown-menu-label)[data-inset] { padding-inline-start: 28px; } .sprout-dropdown-menu-sub-chevron { color: var(--sprout-muted); margin-inline-start: auto; } .sprout-dropdown-menu-choice { padding-inline-end: 32px; } .sprout-dropdown-menu-indicator { pointer-events: none; justify-content: center; align-items: center; display: flex; position: absolute; inset-inline-end: 8px; } .sprout-dropdown-menu-separator { background: var(--sprout-line); height: 1px; margin: 4px -4px; } .sprout-dropdown-menu-shortcut { color: var(--sprout-muted); font-size: var(--sprout-text-xs); letter-spacing: .08em; white-space: nowrap; flex-shrink: 0; margin-inline-start: auto; padding-inline-start: 12px; } .sprout-dropdown-menu-item[data-highlighted] .sprout-dropdown-menu-shortcut { color: var(--sprout-text); } @media (pointer: coarse) { .sprout-dropdown-menu-item { min-height: 2.75rem; } } @media (forced-colors: active) { .sprout-dropdown-menu-item[data-highlighted], .sprout-dropdown-menu-sub-trigger[data-popup-open] { outline-offset: -1px; outline: 2px solid highlight; } } @media (prefers-reduced-motion: no-preference) { .sprout-dropdown-menu-content { transition: opacity var(--sprout-motion-fast) var(--sprout-motion-ease), scale var(--sprout-motion-fast) var(--sprout-motion-ease); } .sprout-dropdown-menu-content[data-starting-style], .sprout-dropdown-menu-content[data-ending-style] { opacity: 0; scale: .96; } } }Import it from
@/components/ui/dropdown-menu. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/dropdown-menu.
Usage
import { Button } from "@tulipfarm/sprout/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@tulipfarm/sprout/dropdown-menu";
<DropdownMenu>
<DropdownMenuTrigger
render={<Button variant="ghost" size="icon-sm" aria-label="Actions for row 1042" />}
>
<MoreH size={16} aria-hidden="true" />
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuGroup>
<DropdownMenuItem onClick={edit}>Edit row</DropdownMenuItem>
<DropdownMenuItem onClick={history}>History</DropdownMenuItem>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuItem variant="destructive" onClick={remove}>
Delete row
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>Pass a Button to DropdownMenuTrigger through render. Icon-only triggers need an aria-label. Disable the trigger with disabled on either part, and set aria-busy while work runs.
Sizes
DropdownMenuContent size is "anchor" (the default: as wide as the trigger, at least 8rem) or "menu" (a fixed 16rem). Use anchor for text triggers like “Selected actions” and short row menus. Use menu for icon triggers with icon items, longer labels, and two-line choices. Both stay inside the viewport and scroll when tall.
Row and page actions
A More button opens actions for one row or page. Icon triggers align the menu to their end.
Placement
Set side, align, sideOffset, and alignOffset. Menus open below and start-aligned by default. Composers and footers use side="top". The menu flips when there is no room.
Chat
The composer opens upward with two-line choices. The header menu disables actions while a reply is sending.
States
A busy trigger changes its label and sets aria-busy. Items take disabled; they stay readable at half opacity and can’t be chosen. When work finishes, show the result next to the trigger and offer only the actions that still apply.
Selection actions
Narrow toolbars fold bulk actions into one menu. The trigger shows progress and turns busy while work runs.
Checkboxes and radios
DropdownMenuCheckboxItem and DropdownMenuRadioItem show a check on the right. They keep the menu open so people can change several options; filters also pass closeOnClick={false} to say so outright. Pass closeOnClick to close after one choice.
Checkbox menus
Filters and column pickers keep the menu open with closeOnClick={false}. The last visible column can’t be hidden.
Links and submenus
Render an item as a link with render={<a href="…" />} or your router’s link. DropdownMenuSub nests a menu: the DropdownMenuSubTrigger adds a chevron and opens DropdownMenuSubContent to the side. Long names truncate inside the 16rem menu.
Sidebar menus
The workspace menu opens below with a switcher submenu. The account menu opens upward with a theme submenu. Items are links.
Controlled
Control the menu with open and onOpenChange to open it from a shortcut. finalFocus on the content decides where focus lands when it closes.
Controlled
Focus the card and press Shift + F10 or the Menu key. The menu opens through open and onOpenChange, then finalFocus returns to the card.
Favorite: off · View: List
No action selected.
Menubar
import { Menubar } from "@base-ui/react/menubar";
<Menubar>
<DropdownMenu>
<DropdownMenuTrigger className="menubar-trigger">File</DropdownMenuTrigger>
<DropdownMenuContent alignOffset={-4} sideOffset={8} className="min-w-48">
<DropdownMenuItem>New task<DropdownMenuShortcut>⌘ N</DropdownMenuShortcut></DropdownMenuItem>
<DropdownMenuItem inset>Duplicate</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</Menubar>Menubar
Each menu is a DropdownMenu inside Base UI’s Menubar. Arrow keys move between menus; inset aligns text with icon rows.
Layout: Board
Accessibility
The trigger has aria-haspopup="menu" and aria-expanded. Enter, Space, and Arrow Down open the menu. Arrow keys move, typing jumps to a matching item, Arrow Right opens a submenu and Arrow Left closes it, and Escape closes the menu and returns focus. Disabled items can still be reached with arrow keys so people know they exist, but they can’t be chosen.
Menus fade and scale in from the trigger over 120ms. Motion turns off when reduced motion is requested. In forced-colors mode the highlighted item gets an outline.
Theme tokens
Menus use --sprout-surface, --sprout-line, --sprout-hover, --sprout-text, --sprout-muted, --sprout-danger, --sprout-danger-subtle, --sprout-shadow-overlay, and the panel and control radii. They need no brand color, so they look the same with the neutral and TulipFarm themes in light and dark mode.