Dropdown Menu
WebDisplays a menu of actions or options to the user, triggered by a button.
Installation
pnpm dlx cubix-ui@latest add dropdown-menu --base ariaUsage
import { Button } from "@/components/cubix/button"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/cubix/dropdown-menu"
<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).
DropdownMenu
├── DropdownMenuTrigger
└── DropdownMenuContent
├── DropdownMenuGroup
│ ├── DropdownMenuLabel
│ └── DropdownMenuItem
│ └── DropdownMenuShortcut
├── DropdownMenuSeparator
├── DropdownMenuCheckboxItem
├── DropdownMenuRadioGroup
│ └── DropdownMenuRadioItem
└── DropdownMenuSub
├── DropdownMenuSubTrigger
└── DropdownMenuSubContentAccessibility
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.
| Key | Action |
|---|---|
| Enter / Space / ArrowDown | On the trigger, opens the menu and focuses the first item. |
| ArrowDown / ArrowUp | Moves focus to the next or previous item. |
| Home / End | Moves focus to the first or last item. |
| Enter / Space | Activates the focused item. Checkbox and radio items toggle and keep the menu open. |
| ArrowLeft / ArrowRight | On 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. |
| Escape | Closes the menu and returns focus to the trigger. |
| Character keys | Moves 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
| Prop | Type | Default | Description |
|---|---|---|---|
| dir | "ltr" | "rtl" | - | Text direction. Portaled menus inherit this so RTL layout and alignment stay correct. Defaults to the closest dir on the page. |
| lang | string | - | Document language on the trigger and portaled content (e.g. "fa"). Enables IRANSans metrics and zero letter-spacing for Arab script. |
| open | boolean | - | Controlled open state. Omit to use uncontrolled mode. |
| defaultOpen | boolean | false | Initial open state when uncontrolled. |
| onOpenChange | (open: boolean) => void | - | Called when the open state changes. |
| children | React.ReactNode | - | A DropdownMenuTrigger and a DropdownMenuContent. |
DropdownMenuTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
| render | React.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. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | Trigger content. Click, Enter, Space or ArrowDown opens the menu. |
DropdownMenuContent
| Prop | Type | Default | Description |
|---|---|---|---|
| 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. |
| sideOffset | number | 4 | Distance in pixels between the trigger and the menu. |
| alignOffset | number | 0 | Offset in pixels along the alignment axis. |
| dir | "ltr" | "rtl" | - | Overrides the direction inherited from DropdownMenu for this menu. |
| lang | string | - | Overrides the language inherited from DropdownMenu for this menu. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). The menu is as wide as its content, with a minimum of 150px. |
| children | React.ReactNode | - | Menu items, groups, separators and submenus. |
DropdownMenuItem
| Prop | Type | Default | Description |
|---|---|---|---|
| inset | boolean | - | 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. |
| disabled | boolean | - | Disables the menu item. Base UI keeps it focusable with the arrow keys. Radix UI and React Aria skip it. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | Item content. An icon placed before the text sits at the start of the item. Selecting the item closes the menu. |
DropdownMenuLabel
| Prop | Type | Default | Description |
|---|---|---|---|
| inset | boolean | - | Adds start padding to align with items that have an icon. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | Label text. Place it first inside a DropdownMenuGroup or DropdownMenuRadioGroup so it names the group for screen readers. |
DropdownMenuCheckboxItem
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | boolean | - | Controlled checked state of the checkbox item. |
| defaultChecked | boolean | - | 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. |
| closeOnClick | boolean | false | Close 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"). |
| inset | boolean | - | Adds start padding for alignment. |
| disabled | boolean | - | Disables the checkbox item. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
DropdownMenuRadioGroup
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | Controlled value of the selected radio item. |
| defaultValue | string | - | 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. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | An optional DropdownMenuLabel followed by DropdownMenuRadioItem elements. |
DropdownMenuRadioItem
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | 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"). |
| closeOnClick | boolean | false | Close the menu after this item is selected. |
| inset | boolean | - | Adds start padding for alignment. |
| disabled | boolean | - | Disables the radio item. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
DropdownMenuShortcut
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | Key combination shown at the inline end of the item. The keys always read left to right, also in RTL. |
DropdownMenuSubTrigger
| Prop | Type | Default | Description |
|---|---|---|---|
| inset | boolean | - | Adds start padding for alignment. |
| disabled | boolean | - | Disables the submenu trigger. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.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
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.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.