DropdownMenu
A menu of actions and settings behind a button, with groups, checkbox and radio items, submenus and a destructive item.
A dropdown menu opens from a button with a list of actions, such as the actions of a table row, or settings that apply at once. It is built on Base UI's menu. For a choice that is a form value, use a select; for actions on a right click, a context menu.
Last action: nothing yet · archived hidden · sorted by name
// apps/docs/examples/ui/dropdown-menu.tsx'use client';
import {useState} from 'react';import { CopyIcon, MoreHorizontalIcon, PencilIcon, Trash2Icon,} from 'lucide-react';
import {Button} from '@workspace/active-ui/components/primitives/button';import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger,} from '@workspace/active-ui/components/primitives/dropdown-menu';
/** * The actions of one row behind a button: plain items, a setting that is on * or off, one choice out of several, a submenu, and a destructive action set * apart. What each item did is printed below, because a menu only reports * the choice. */export default function DropdownMenuExample() { const [last, setLast] = useState('nothing yet'); const [archived, setArchived] = useState(false); const [sort, setSort] = useState('name'); return ( <div className="flex flex-col items-center gap-4"> <DropdownMenu> <DropdownMenuTrigger render={ <Button variant="outline" size="icon" aria-label="Scheme actions" /> } > <MoreHorizontalIcon aria-hidden /> </DropdownMenuTrigger> <DropdownMenuContent className="w-56"> <DropdownMenuGroup> <DropdownMenuLabel>Pension scheme 2026</DropdownMenuLabel> <DropdownMenuItem onClick={() => setLast('Edit')}> <PencilIcon aria-hidden /> Edit </DropdownMenuItem> <DropdownMenuItem onClick={() => setLast('Duplicate')}> <CopyIcon aria-hidden /> Duplicate </DropdownMenuItem> <DropdownMenuSub> <DropdownMenuSubTrigger>Export as</DropdownMenuSubTrigger> <DropdownMenuSubContent> <DropdownMenuItem onClick={() => setLast('Export as CSV')}> CSV </DropdownMenuItem> <DropdownMenuItem onClick={() => setLast('Export as PDF')}> PDF </DropdownMenuItem> </DropdownMenuSubContent> </DropdownMenuSub> </DropdownMenuGroup> <DropdownMenuSeparator /> <DropdownMenuCheckboxItem checked={archived} onCheckedChange={setArchived} > Show archived versions </DropdownMenuCheckboxItem> <DropdownMenuSeparator /> <DropdownMenuGroup> <DropdownMenuLabel>Sort participants by</DropdownMenuLabel> <DropdownMenuRadioGroup value={sort} onValueChange={setSort}> <DropdownMenuRadioItem value="name">Name</DropdownMenuRadioItem> <DropdownMenuRadioItem value="joined"> Date joined </DropdownMenuRadioItem> </DropdownMenuRadioGroup> </DropdownMenuGroup> <DropdownMenuSeparator /> <DropdownMenuItem variant="destructive" onClick={() => setLast('Delete')} > <Trash2Icon aria-hidden /> Delete </DropdownMenuItem> </DropdownMenuContent> </DropdownMenu> <p className="text-muted-foreground text-sm" aria-live="polite"> Last action: {last} · archived {archived ? 'shown' : 'hidden'} · sorted by {sort} </p> </div> );}Usage#
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger,} from '@workspace/active-ui/components/primitives/dropdown-menu';
<DropdownMenu> <DropdownMenuTrigger render={<Button variant="outline" />}> Actions </DropdownMenuTrigger> <DropdownMenuContent> <DropdownMenuItem onClick={edit}>Edit</DropdownMenuItem> <DropdownMenuItem variant="destructive" onClick={remove}> Delete </DropdownMenuItem> </DropdownMenuContent></DropdownMenu>;Anatomy#
DropdownandMenu Dropdown: the open state and the button that opens it.Menu Trigger Dropdown: the list, placed byMenu Content side(defaultbottom) andalign(defaultstart). It is as wide as its trigger, at least8rem; set a width withclass.Name Dropdown: an action, run byMenu Item on; the menu closes after it.Click variant="destructive"colours an action that deletes.insetaligns an item without an icon with items that have one.Dropdown: a setting that is on or off (Menu Checkbox Item checked,on). The menu stays open after it, so several settings can be changed at once.Checked Change DropdownwithMenu Radio Group Dropdown: one choice out of several (Menu Radio Item value,on).Value Change DropdownwithMenu Group Dropdown: a labelled group. A label belongs inside a group.Menu Label DropdownwithMenu Sub DropdownandMenu Sub Trigger Dropdown: a submenu.Menu Sub Content DropdownandMenu Separator Dropdown. A shortcut only shows a key combination; binding the keys is your application's work.Menu Shortcut
What your application provides#
An accessible name for an icon-only trigger.
What each item does, and the state of checkbox and radio items.
A confirmation for a destructive item that cannot be undone, such as an alert dialog.
Accessibility and keyboard#
The trigger opens the menu with
Enter,Spaceor↓, and moves the focus to the first item.↓and↑move between items, typing a letter jumps to an item that starts with it,→opens a submenu and←closes it,Enterruns the item, andEscapecloses the menu and returns the focus to the trigger.The list is a
role="menu"; items aremenuitem,menuitemcheckboxormenuitemradio.
API#
DropdownMenuContent#
Import from @workspace/
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
DropdownMenuItem#
Import from @workspace/
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
Other parts#
DropdownMenu
All props come from the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Takes only the props listed.
DropdownMenuPortal
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
DropdownMenuTrigger
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
DropdownMenuGroup
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
DropdownMenuLabel
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
DropdownMenuCheckboxItem
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
DropdownMenuRadioGroup
All props come from the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
DropdownMenuRadioItem
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
DropdownMenuSeparator
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
DropdownMenuSub
All props come from the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Takes only the props listed.
DropdownMenuSubTrigger
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
DropdownMenuSubContent
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
Parts that take only their element’s attributes
This page adapts the Dropdown Menu documentation of shadcn/ui (MIT licence) to this package; see Third-party notices.