# DropdownMenu
A dropdown menu triggers a single command from a set of actions, with support for groups, submenus, checkbox items, radio items, shortcut hints, and destructive actions.
## Use cases
- **Suitable**: User menus, inline action menus, and command lists that need groups or submenus
- **Suitable**: Settings that show checked or selected state inside the menu
- **Not suitable**: Overlays that need large text input or complex forms (use `dialog` or `popover`)
- **Not suitable**: Cases that only need a regular button (use `button`)
## Usage
```tsx
import {
DropdownMenu,
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
} from "@lcui/react"
```
```tsx
My AccountProfileSettingsLog out
```
## Composition
Use the following composition to build a `DropdownMenu`:
```
DropdownMenu
├── DropdownMenuTrigger
└── DropdownMenuContent (Portal)
├── DropdownMenuLabel
├── DropdownMenuGroup
│ ├── DropdownMenuItem
│ └── DropdownMenuCheckboxItem
├── DropdownMenuSeparator
├── DropdownMenuGroup
│ └── DropdownMenuRadioGroup
│ ├── DropdownMenuRadioItem
│ └── DropdownMenuRadioItem
└── DropdownMenuSub
├── DropdownMenuSubTrigger
└── DropdownMenuSubContent (Portal)
└── DropdownMenuItem
```
## Examples
### Basic
A basic menu with a group label, a separator, and a disabled item at the end.
### Submenu
Place `DropdownMenuSubTrigger` and `DropdownMenuSubContent` inside `DropdownMenuSub`. Hovering or clicking the trigger opens the submenu. Submenu content is also rendered through a Portal.
### Shortcuts
`DropdownMenuShortcut` only displays a shortcut hint; it does not bind a real shortcut. While the menu is open, typing a letter triggers typeahead: for example, pressing `s` moves to the menu item that starts with S. It only changes the highlight and never runs the command. Pressing the same letter repeatedly cycles through items with the same initial.
### Icons
Place an icon before the item label to make the action easier to recognize.
### Checkboxes
`DropdownMenuCheckboxItem` toggles its `checked` status when activated and keeps the menu open so several items can be toggled in a row. Set the initial state with the `checked` attribute.
### Checkboxes with icons
Add icons before the checkbox labels to make each option easier to recognize. The check indicator is still inserted automatically at the right side by the widget.
### Radio group
When the `value` of `DropdownMenuRadioGroup` matches the `value` of a `DropdownMenuRadioItem`, that item enters the selected state. Switching options keeps the menu open.
### Radio with icons
Radio items can also show icons before their labels, which is useful for choices such as payment methods.
### Disabled and destructive
Setting `disabled` on an item prevents pointer and keyboard activation. Setting `variant="destructive"` renders the item in the danger color.
### Avatar menu
Use a circular avatar button as the trigger to build an account switcher menu.
### Complex
Combine icons, groups, separators, checkbox items, submenus, and shortcut hints to build a complete account menu.
## API Reference
### DropdownMenu
The menu state container that manages open state, focus, and keyboard navigation.
### DropdownMenuTrigger
The trigger area that toggles the menu open state when clicked.
### DropdownMenuContent
The menu panel rendered through a Portal. It handles positioning, outside-click closing, and item layout.
### DropdownMenuGroup
A container that groups related menu items.
### DropdownMenuLabel
A menu group heading that is skipped by keyboard navigation.
### DropdownMenuItem
A regular command item that closes the menu and emits `select` when activated.
### DropdownMenuCheckboxItem
A menu item with a checked state. Activating it toggles the state and emits `checked-change`.
### DropdownMenuRadioGroup
A container that manages a mutually exclusive radio value. The checked state of its items is synchronized from `value`.
### DropdownMenuRadioItem
A radio menu item. Activating it updates the value of its radio group and emits `value-change`.
### DropdownMenuSeparator
A thin divider between menu groups.
### DropdownMenuShortcut
Shortcut hint text aligned to the right side of a menu item.
### DropdownMenuSub
The submenu state container.
### DropdownMenuSubTrigger
The item that opens the submenu. Hovering or clicking it opens the submenu.
### DropdownMenuSubContent
The submenu panel rendered through a Portal. It opens to the right of the trigger by default.
## Caveats
:::note
**Menu content is managed by Portal.** Put `DropdownMenuContent` inside `DropdownMenu`; do not mount it to `ui_root` manually.
:::
:::tip
**Keyboard navigation is built in.** Once the menu is open, use `ArrowUp` / `ArrowDown` to cycle the highlight, `Home` / `End` to jump to the first or last item, `Enter` / `Space` to activate, `ArrowRight` to enter a submenu, `ArrowLeft` to return to the parent, and `Escape` to close the submenu and then the root menu.
:::
:::caution
**Automatic collision flipping is not supported yet.** The menu does not flip or clamp itself against window edges. Set `side` / `align` manually when needed.
:::
:::caution
**RTL is not implemented yet.** The current layout and arrow-key behavior assume LTR.
:::