Dropdown Menu

Web

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

Installation

pnpm dlx cubix-ui@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" />}>پرونده</DropdownMenuTrigger>
  <DropdownMenuContent>
    <DropdownMenuGroup>
      <DropdownMenuLabel>پنجره‌ها</DropdownMenuLabel>
      <DropdownMenuItem>زبانه جدید</DropdownMenuItem>
      <DropdownMenuItem>پنجره جدید</DropdownMenuItem>
      <DropdownMenuItem disabled>پنجره ناشناس</DropdownMenuItem>
    </DropdownMenuGroup>
    <DropdownMenuSeparator />
    <DropdownMenuItem>چاپ</DropdownMenuItem>
  </DropdownMenuContent>
</DropdownMenu>

Composition

Pass render={<Button />} to style the trigger as a Cubix Button. The menu reads dir and lang from the closest element on the page and carries them into the portaled content, so it opens aligned to the start edge of the trigger (the right edge in RTL).

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

Accessibility

The trigger exposes aria-haspopup and aria-expanded, the content is a menu, and checkbox and radio items announce their checked state. Focus moves into the menu when it opens and returns to the trigger when it closes. Give icon-only triggers an aria-label.

KeyAction
Enter / Space / ArrowDownOn the trigger, opens the menu and focuses the first item.
ArrowDown / ArrowUpMoves focus to the next or previous item.
Home / EndMoves focus to the first or last item.
Enter / SpaceActivates the focused item. Checkbox and radio items toggle and keep the menu open.
ArrowLeft / ArrowRightOn a submenu trigger, the key toward the inline end opens the submenu (ArrowLeft in RTL). The opposite key closes it and returns focus to the trigger.
EscapeCloses the menu and returns focus to the trigger.
Character keysMoves focus to the next item whose label starts with the typed character.

Examples

Basic

Group related items under a DropdownMenuLabel and split sections with DropdownMenuSeparator. Set disabled on an item to lock it.

Submenu

Nest menus with DropdownMenuSub, DropdownMenuSubTrigger and DropdownMenuSubContent. In RTL the submenu opens to the left and ArrowLeft opens it from the keyboard.

Checkboxes

Use DropdownMenuCheckboxItem for options that turn on and off. The menu stays open while toggling, and without checked the state is kept when the menu closes and opens again.

Radio group

Use DropdownMenuRadioGroup with DropdownMenuRadioItem when only one option can be selected. Here the trigger shows the current choice.

Tick indicator

Set indicator="check" to show a plain tick instead of the Cubix Checkbox or Radio. On a radio group it applies to every item in the group.

Destructive

Use variant="destructive" on DropdownMenuItem for irreversible actions such as delete. The icon-only trigger is named with aria-label.

API Reference

Note: Parts render data-slot attributes (dropdown-menu-trigger, dropdown-menu-content, dropdown-menu-group, dropdown-menu-label, dropdown-menu-item, dropdown-menu-checkbox-item, dropdown-menu-radio-group, dropdown-menu-radio-item, dropdown-menu-separator, dropdown-menu-shortcut, dropdown-menu-sub-trigger, dropdown-menu-sub-content) for targeting in tests and parent selectors. Use the same props on Base UI, React Aria, and Radix.

DropdownMenu

PropTypeDefaultDescription
dir"ltr" | "rtl"-Text direction. Portaled menus inherit this so RTL layout and alignment stay correct. Defaults to the closest dir on the page.
langstring-Document language on the trigger and portaled content (e.g. "fa"). Enables IRANSans metrics and zero letter-spacing for Arab script.
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-A DropdownMenuTrigger and a DropdownMenuContent.

DropdownMenuTrigger

PropTypeDefaultDescription
renderReact.ReactElement-Renders the trigger as another element, e.g. render={<Button variant="outline" />}. Base UI merges onto the element. React Aria renders its own pressable button and applies the Button's variant, size, className and aria-label. Radix UI uses asChild with the Button as the child instead.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-Trigger content. Click, Enter, Space or ArrowDown opens the menu.

DropdownMenuContent

PropTypeDefaultDescription
side"top" | "right" | "bottom" | "left""bottom"Preferred side of the trigger to open on. The menu flips when there is not enough room.
align"start" | "center" | "end""start"Alignment against the trigger. start follows the text direction, so in RTL the menu lines up with the right edge of the trigger.
sideOffsetnumber4Distance in pixels between the trigger and the menu.
alignOffsetnumber0Offset in pixels along the alignment axis.
dir"ltr" | "rtl"-Overrides the direction inherited from DropdownMenu for this menu.
langstring-Overrides the language inherited from DropdownMenu for this menu.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins). The menu is as wide as its content, with a minimum of 150px.
childrenReact.ReactNode-Menu items, groups, separators and submenus.

DropdownMenuItem

PropTypeDefaultDescription
insetboolean-Adds start padding to align with items that have an icon.
variant"default" | "destructive""default"Visual style of the menu item. Use destructive for irreversible actions.
disabledboolean-Disables the menu item. Base UI keeps it focusable with the arrow keys. Radix UI and React Aria skip it.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-Item content. An icon placed before the text sits at the start of the item. Selecting the item closes the menu.

DropdownMenuLabel

PropTypeDefaultDescription
insetboolean-Adds start padding to align with items that have an icon.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-Label text. Place it first inside a DropdownMenuGroup or DropdownMenuRadioGroup so it names the group for screen readers.

DropdownMenuCheckboxItem

PropTypeDefaultDescription
checkedboolean-Controlled checked state of the checkbox item.
defaultCheckedboolean-Initial checked state when uncontrolled. The state is kept when the menu closes and opens again.
onCheckedChange(checked: boolean) => void-Called when the checked state changes.
closeOnClickbooleanfalseClose the menu after toggling. By default the menu stays open so several options can be changed in one go.
indicator"check" | "control""control"What shows at the end of the item: the Cubix Checkbox ("control") or a plain tick that only appears when checked ("check").
insetboolean-Adds start padding for alignment.
disabledboolean-Disables the checkbox item.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

DropdownMenuRadioGroup

PropTypeDefaultDescription
valuestring-Controlled value of the selected radio item.
defaultValuestring-Initial value when uncontrolled. The selection is kept when the menu closes and opens again.
onValueChange(value: string) => void-Called when the selected value changes. The menu stays open unless the item sets closeOnClick.
indicator"check" | "control""control"Indicator for every item in the group: the Cubix Radio ("control") or a plain tick ("check"). An item's own indicator prop overrides it.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-An optional DropdownMenuLabel followed by DropdownMenuRadioItem elements.

DropdownMenuRadioItem

PropTypeDefaultDescription
valuestring-Value of this item (required). It is selected when it matches the group value.
indicator"check" | "control"-Overrides the group indicator for this item: the Cubix Radio ("control") or a plain tick ("check").
closeOnClickbooleanfalseClose the menu after this item is selected.
insetboolean-Adds start padding for alignment.
disabledboolean-Disables the radio item.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

DropdownMenuShortcut

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-Key combination shown at the inline end of the item. The keys always read left to right, also in RTL.

DropdownMenuSubTrigger

PropTypeDefaultDescription
insetboolean-Adds start padding for alignment.
disabledboolean-Disables the submenu trigger.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-Trigger content. A chevron is added at the end. Hover, click, Enter or the arrow key toward the end side (ArrowLeft in RTL) opens the submenu.

DropdownMenuSubContent

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.ReactNode-Submenu items. The submenu opens toward the end side of the parent menu (the left in RTL) and flips when there is not enough room.

DropdownMenuGroup takes className and children, DropdownMenuSeparator takes className, and DropdownMenuSub takes a DropdownMenuSubTrigger followed by a DropdownMenuSubContent.