# Dropdown menu

> A menu of actions opened from a trigger, with separators and keyboard support.

Use a dropdown menu to group actions that don't need to be visible all the time, such as the actions for one row or one project. For choosing a value, use a [select](/docs/components/select); for switching views, a [segmented control](/docs/components/segmented-control).

Pro example source is available to licensed users. See [Pro access](/docs/pro/access).

## Installation

Pro components install from the Aloxe registry with the shadcn CLI. Once per project, add the registry to `components.json` and put a [registry token](/account/tokens) in the `ALOXE_TOKEN` environment variable. [Registry](/docs/pro/registry) has the details.

```json
{
  "registries": {
    "@aloxe": {
      "url": "https://<aloxe-site>/r/{name}.json",
      "headers": { "Authorization": "Bearer ${ALOXE_TOKEN}" }
    }
  }
}
```

Then add the component:

```bash
npx shadcn@latest add @aloxe/dropdown-menu
```

The CLI copies the source into `components/ui/aloxe/`, so it never overwrites your own `ui` components. It also installs `@aloxe/react`, `@aloxe/tokens` and `@base-ui/react`.

Import the tokens once in your global stylesheet, after Tailwind, and add an `@source` for the copied files and one for `@aloxe/react`, so Tailwind generates their classes. `@source` paths are relative to the stylesheet; these assume `src/app/globals.css` and `src/components/ui/aloxe/`.

```css
@import "tailwindcss";
@import "@aloxe/tokens/aloxe.css";
@import "@aloxe/tokens/tailwind.css";
@source "../components/ui/aloxe";
@source "../../node_modules/@aloxe/react/dist";
```

[Installation](/docs/getting-started/installation) covers the theme and brand attributes.

## Usage

```tsx
import { Button } from "@aloxe/react";
import { DropdownMenu, MenuItem, MenuSeparator } from "@/components/ui/aloxe/dropdown-menu";

<DropdownMenu trigger={<Button variant="secondary">Project</Button>}>
  <MenuItem onClick={rename}>Rename</MenuItem>
  <MenuItem onClick={duplicate}>Duplicate</MenuItem>
  <MenuSeparator />
  <MenuItem variant="destructive" onClick={remove}>Delete project</MenuItem>
</DropdownMenu>
```

The `trigger` is one element that accepts a ref, usually a `Button` or an `IconButton`. Each `MenuItem` runs its action in `onClick`, then the menu closes.

The menu opens in a popup attached to the page body. It copies the `data-theme` and `data-brand` of the place the trigger sits in, so it matches a themed panel.

## Examples

### Icons, shortcuts and states

Items take a 16 px `icon` and a `shortcut` keycap. A `disabled` item stays in the list so people learn it exists. Keep `variant="destructive"` for the one action that deletes or revokes, after a separator.

Pro example source is available to licensed users. See [Pro access](/docs/pro/access).

### Icon button trigger

For row actions, use a ghost `IconButton` with a label that names the row, and `align="end"` so the menu lines up with the right edge. An item can be a link with `render={<a href="…" />}`.

Pro example source is available to licensed users. See [Pro access](/docs/pro/access).

## Accessibility

| Key | Action |
| --- | --- |
| Enter, Space or Down | Opens the menu on the first item when the trigger has focus. |
| Up | Opens the menu on the last item. |
| Down and Up | Moves through the items, wrapping at the ends. Disabled items are reached too. |
| Home and End | Moves to the first or last item. |
| A letter | Jumps to the next item starting with it. |
| Enter or Space | Activates the highlighted item and closes the menu. |
| Escape or Tab | Closes the menu and returns focus to the trigger. |

- Follows the WAI-ARIA menu button pattern: the trigger has `aria-haspopup` and `aria-expanded`, the popup has `role="menu"` and is labelled by the trigger.
- Disabled items are announced as disabled (`aria-disabled`) and can't be activated.
- Icons are decorative. Shortcut keycaps are hidden from screen readers: bind the key yourself and add `aria-keyshortcuts` to the item.
- Destructive items differ by their label as well as their colour, so the meaning doesn't rely on colour.

## API reference

Every part accepts `className` and renders a `data-aloxe` attribute you can target in CSS, such as `[data-aloxe="menu-item"]`.

**DropdownMenu** (extends Base UI Menu.Popup)

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `trigger` | `ReactElement` |  | Yes | The element that opens the menu, such as a Button or an IconButton. It gets aria-haspopup and aria-expanded. |
| `children` | `ReactNode` |  | Yes | MenuItem and MenuSeparator elements. |
| `side` | `"top" \| "bottom" \| "left" \| "right"` | `"bottom"` |  | Which side of the trigger the menu opens on. It flips when there isn't room. |
| `align` | `"start" \| "center" \| "end"` | `"start"` |  | How the menu lines up with the trigger along that side. |
| `open` | `boolean` |  |  | Controlled open state. Pair with onOpenChange. |
| `defaultOpen` | `boolean` | `false` |  | Initial open state when uncontrolled. |
| `onOpenChange` | `(open: boolean, details) => void` |  |  | Called when the menu opens or closes. |
| `modal` | `boolean` | `true` |  | While open, blocks page scroll and pointer interaction outside the menu. |
| `disabled` | `boolean` | `false` |  | Disables the trigger. |
| `className` | `string` |  |  | Classes for the menu popup, such as a width (w-56). |

**MenuItem** (extends Base UI Menu.Item)

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `variant` | `"default" \| "destructive"` | `"default"` |  | destructive uses the danger text colour. Keep it for the one action that deletes or revokes. |
| `icon` | `ReactNode` |  |  | A 16 px line icon before the label. Decorative. |
| `shortcut` | `ReactNode` |  |  | A keycap after the label, such as ⌘D. Visual only: bind the key yourself and pass aria-keyshortcuts. |
| `onClick` | `(event) => void` |  |  | Runs the action. The menu closes afterwards. |
| `closeOnClick` | `boolean` | `true` |  | false keeps the menu open after the item is activated. |
| `disabled` | `boolean` | `false` |  | Keeps the item in the list, reachable with the arrow keys, but it can't be activated. |
| `render` | `ReactElement` |  |  | Renders the item as another element, such as <a href="…" /> for navigation. |
| `className` | `string` |  |  | Merged with the default classes. |

**MenuSeparator** (extends Base UI Menu.Separator)

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `className` | `string` |  |  | Merged with the default classes. |

## Figma

Matches the **Dropdown menu**, **Menu item** and **Menu separator** components in the Pro Figma file. Menu item `Type` (`Default`, `Destructive`) maps to `variant`; `Show icon` and `Show shortcut` map to `icon` and `shortcut`.

See [Figma](/docs/getting-started/figma) for where to get the file and how its names map to code.

## Pro

Dropdown menu is part of Aloxe Pro. The previews on this page are open to everyone; the Code tab shows the example source once you sign in with a Pro license. See [Access and licenses](/docs/pro/access) and [Pricing](/pricing#pro).
