Dropdown Menu

Displays a menu of actions or links to the user, triggered by a button.

Installation

pnpm dlx cubix@latest add dropdown-menu

Usage

Import
import { Button } from "@/components/cubix/button"
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuGroup,
  DropdownMenuItem,
  DropdownMenuLabel,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from "@/components/cubix/dropdown-menu"
Example
<DropdownMenu>
  <DropdownMenuTrigger render={<Button variant="outline" />}>
Open
</DropdownMenuTrigger>
  <DropdownMenuContent>
    <DropdownMenuGroup>
      <DropdownMenuLabel>My Account</DropdownMenuLabel>
      <DropdownMenuItem>Profile</DropdownMenuItem>
      <DropdownMenuItem>Billing</DropdownMenuItem>
    </DropdownMenuGroup>
    <DropdownMenuSeparator />
    <DropdownMenuGroup>
      <DropdownMenuItem>Team</DropdownMenuItem>
      <DropdownMenuItem>Subscription</DropdownMenuItem>
    </DropdownMenuGroup>
  </DropdownMenuContent>
</DropdownMenu>

Composition

Use the following composition to build a DropdownMenu:

Composition
DropdownMenu
├── DropdownMenuTrigger
└── DropdownMenuContent
    ├── DropdownMenuGroup
       ├── DropdownMenuLabel
       ├── DropdownMenuItem
       └── DropdownMenuItem
    ├── DropdownMenuSeparator
    ├── DropdownMenuGroup
       ├── DropdownMenuLabel
       ├── DropdownMenuCheckboxItem
       └── DropdownMenuCheckboxItem
    ├── DropdownMenuSeparator
    ├── DropdownMenuGroup
       ├── DropdownMenuLabel
       └── DropdownMenuRadioGroup
           ├── DropdownMenuRadioItem
           └── DropdownMenuRadioItem
    └── DropdownMenuSub
        ├── DropdownMenuSubTrigger
        └── DropdownMenuSubContent
            └── DropdownMenuGroup
                ├── DropdownMenuLabel
                ├── DropdownMenuItem
                └── DropdownMenuItem

Examples

Basic

A basic dropdown menu with labels and separators.

Submenu

Use DropdownMenuSub to nest secondary actions.

Shortcuts

Add DropdownMenuShortcut to show keyboard hints.

Icons

Combine icons with labels for quick scanning.

Checkboxes

Use DropdownMenuCheckboxItem for toggles.

Checkboxes Icons

Add icons to checkbox items.

Radio Group

Use DropdownMenuRadioGroup for exclusive choices.

Radio Icons

Show radio options with icons.

Destructive

Use variant="destructive" for irreversible actions.

Avatar

An account switcher dropdown triggered by an avatar.

Complex

A richer example combining groups, icons, and submenus.

RTL

Wrap the menu in a RTL container to mirror layout and chevrons.

API Reference

Note: The menu is not modal. Escape, Tab, and clicking outside close it, and focus returns to the trigger. Use arrow keys to move between items.

DropdownMenu

The container that wraps the trigger and content and manages open state.

PropTypeDefaultDescription
openboolean-Controlled open state. Omit to use uncontrolled mode.
defaultOpenbooleanfalseInitial open state when uncontrolled.
onOpenChange(open: boolean) => void-Called when the open state changes.
childrenReact.ReactNode-The trigger, content, and nested menu parts.

DropdownMenuTrigger

The element that opens the menu. Use render to merge onto a Button.

PropTypeDefaultDescription
renderReact.ReactElement-Render the trigger as another element (e.g. a Button).
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

DropdownMenuContent

The menu panel rendered in a portal next to the trigger.

PropTypeDefaultDescription
side"top" | "right" | "bottom" | "left""bottom"Preferred side of the trigger to render the menu on.
align"start" | "center" | "end""start"Alignment along the opposite axis of `side`.
sideOffsetnumber4Distance in pixels between the trigger and the menu.
alignOffsetnumber0Offset in pixels along the alignment axis.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
...propsReact.ComponentProps<'div'>-All native div attributes are forwarded to the menu panel.

DropdownMenuItem

An action inside the menu. Selecting it closes the menu.

PropTypeDefaultDescription
insetboolean-Indent the item to align with items that have a leading icon.
variant"default" | "destructive""default"Visual treatment. Use destructive for irreversible actions.
disabledboolean-Prevents selection and removes the item from keyboard flow.
onSelect(event: Event) => void-Called when the item is chosen. The menu closes afterwards.

DropdownMenuCheckboxItem

A checkable item. The menu stays open after toggling.

PropTypeDefaultDescription
checkedboolean-Controlled checked state.
defaultCheckedboolean-Initial checked state when uncontrolled.
onCheckedChange(checked: boolean) => void-Called when the checked state changes. The menu stays open.
disabledboolean-Prevents toggling the item.

DropdownMenuRadioGroup

A set of mutually exclusive items. The menu stays open after a change.

PropTypeDefaultDescription
valuestring-Controlled selected value.
defaultValuestring-Initial selected value when uncontrolled.
onValueChange(value: string) => void-Called when a radio item is selected. The menu stays open.

DropdownMenuRadioItem

One option inside a radio group. value is required.

PropTypeDefaultDescription
valuestring-The unique value represented by this radio item.
disabledboolean-Prevents selecting the item.