Unified UI

Dropdown Menu

A context menu component with items, checkboxes, radios, submenus, and keyboard navigation. Built on Radix UI.

Overview

The DropdownMenu component provides a context menu triggered by a button or other interactive element. It supports standard menu items, checkbox items, radio groups, submenus, labels, separators, and keyboard shortcuts — all built on Radix UI's DropdownMenu primitive for full accessibility.


Installation

Install the component via the CLI in one command.

npx @work-rjkashyap/unified-ui add dropdown-menu
pnpm dlx @work-rjkashyap/unified-ui add dropdown-menu
npx @work-rjkashyap/unified-ui add dropdown-menu
bunx @work-rjkashyap/unified-ui add dropdown-menu

If you haven't initialized your project yet, run npx @work-rjkashyap/unified-ui init first. See the CLI docs for details.

Or install the full package

Use this approach if you prefer to install the entire design system as a dependency instead of copying individual components.

npm install @work-rjkashyap/unified-ui
pnpm add @work-rjkashyap/unified-ui
yarn add @work-rjkashyap/unified-ui
bun add @work-rjkashyap/unified-ui

Anatomy

import {
	DropdownMenu,
	DropdownMenuTrigger,
	DropdownMenuContent,
	DropdownMenuItem,
	DropdownMenuCheckboxItem,
	DropdownMenuRadioGroup,
	DropdownMenuRadioItem,
	DropdownMenuLabel,
	DropdownMenuSeparator,
	DropdownMenuShortcut,
	DropdownMenuGroup,
	DropdownMenuSub,
	DropdownMenuSubTrigger,
	DropdownMenuSubContent,
} from "@work-rjkashyap/unified-ui";

Examples

Basic Usage

With Labels and Separators

With Groups

Keyboard Shortcuts

Danger / Destructive Items

Disabled Items


Checkbox Items

Use DropdownMenuCheckboxItem for togglable menu items. Manage the checked state externally.

Radio Items

Use DropdownMenuRadioGroup and DropdownMenuRadioItem for single-select option groups.

With onSelect Handler

Each DropdownMenuItem fires an onSelect callback when clicked or activated via keyboard.

Full Kitchen Sink

Combining all features into a comprehensive example.


Props

PropTypeDefaultDescription
openbooleanControlled open state.
defaultOpenbooleanDefault open state (uncontrolled).
onOpenChange(open: boolean) => voidCallback when the open state changes.
modalbooleantrueWhether the menu blocks interaction with the rest of the page.

Uses Radix UI's trigger API. Use asChild to render as your own element.

PropTypeDefaultDescription
asChildbooleanfalseMerge props onto the child element.
PropTypeDefaultDescription
side"top" | "right" | "bottom" | "left""bottom"Which side of the trigger to place the menu.
align"start" | "center" | "end""start"Alignment along the side axis.
sideOffsetnumber4Distance in px from the trigger.
classNamestringAdditional CSS classes.
PropTypeDefaultDescription
variant"default" | "danger""default"Visual variant. Use "danger" for destructive actions.
disabledbooleanfalseWhether the item is disabled.
onSelect(event: Event) => voidCallback when the item is selected (click or keyboard).
classNamestringAdditional CSS classes.
PropTypeDefaultDescription
checkedbooleanControlled checked state.
onCheckedChange(checked: boolean) => voidCallback when checked state changes.
disabledbooleanfalseWhether the item is disabled.
classNamestringAdditional CSS classes.
PropTypeDefaultDescription
valuestringControlled selected value.
onValueChange(value: string) => voidCallback when the selection changes.
PropTypeDefaultDescription
valuestringrequiredThe value of this radio item.
disabledbooleanfalseWhether the item is disabled.
classNamestringAdditional CSS classes.
PropTypeDefaultDescription
classNamestringAdditional CSS classes.
PropTypeDefaultDescription
classNamestringAdditional CSS classes.
PropTypeDefaultDescription
classNamestringAdditional CSS classes.
PropTypeDefaultDescription
classNamestringAdditional CSS classes.
PropTypeDefaultDescription
sideOffsetnumber2Distance from the parent menu.
classNamestringAdditional CSS classes.

Accessibility

Built on @radix-ui/react-dropdown-menu which provides full WAI-ARIA Menu pattern compliance.

  • Keyboard navigationArrow Up / Arrow Down to navigate items. Arrow Right to open submenus. Arrow Left to close submenus. Enter / Space to select.
  • Type-ahead — Typing characters focuses matching items.
  • Escape — Closes the menu and returns focus to the trigger.
  • Focus management — Focus is trapped within the menu when open. Returns to the trigger on close.
  • The trigger renders with aria-haspopup="menu" and aria-expanded.
  • Menu items have role="menuitem", checkbox items have role="menuitemcheckbox", radio items have role="menuitemradio".
  • DropdownMenuGroup provides semantic role="group" for assistive technology.
  • Disabled items are excluded from keyboard navigation and marked with aria-disabled.
  • Focus ring is visible on keyboard navigation only (focus-visible).
  • The shortcut text (DropdownMenuShortcut) is purely visual — it does not create actual keyboard bindings.

Design Tokens

TokenUsage
--surface-raisedMenu panel background
--borderMenu border color
--primaryFocused item background highlight
--dangerDanger variant item text color
--muted-foregroundLabel and shortcut text color
--shadow-mdMenu panel elevation shadow
--radius-mdMenu panel border radius
--z-dropdownZ-index for the menu layer
--duration-fastEnter/exit animation timing

On this page