# Dropdown Menu

A list of actions opened from a button. Built on ui-sdk's Menu: arrow keys move, typing jumps to a row, Escape closes and focus returns to the trigger. Rows show keyboard focus with the hover highlight, never a ring, and ticks sit on the right.

- Beta: ready to use; its API can still change in a minor release.
- Category: Overlays

```tsx
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from "@leap-crm/design-system";
```

## Best practices

- Do: Use it for the actions on one record, opened from a button, like Edit, Duplicate and Delete behind an opportunity's ⋯ button.
- Do: Open it from an `IconButton` passed to `DropdownMenuTrigger`'s `render`, with an `aria-label` that names the record, like Opportunity actions. In a table, each row's trigger needs its own name.
- Do: Put Delete, Remove or Archive last, below a `DropdownMenuSeparator`, and set `destructive` on it. The label says what it does, so the red tone is never the only signal.
- Do: Use `DropdownMenuCheckboxItem` and `DropdownMenuRadioItem` for rows that toggle or choose. Their tick sits on the right, so every label starts at the same edge.
- Don't: Give a row a focus ring, a coloured fill or a radius as large as the menu's. Rows show focus with the hover highlight, a chosen row shows a tick, and a row's corners stay smaller than the menu's.
- Don't: Use it to choose a value for a form field, like a matter type, or add a search field to it. Use `Select`, or a `Popover` with `PopoutSearch` for a list that needs searching.

## Keyboard

| Keys | What they do |
| --- | --- |
| Enter, Space, ArrowDown | Open the menu and focus the first item. |
| ArrowUp | Opens the menu and focuses the last item. |
| ArrowDown, ArrowUp | Move between items, skipping separators and labels. |
| Home, End | Move to the first and last items. |
| Typing | Moves to the next item that starts with what was typed. |
| Enter | Runs the focused item, closes the menu and returns focus. |
| ArrowRight, ArrowLeft | Open a submenu, and close it back to its trigger. |
| Escape | Closes the menu and returns focus to the trigger. |
| Tab | Closes the menu. |

## Related

- [Select](./select.md)
- [Popover](./popover.md)
- [Split Button](./split-button.md)
- [Combobox](./combobox.md)

## Examples

What the examples import:

```tsx
import { Archive, Copy, MoreHorizontal, Pencil, Share2, Trash2 } from "lucide-react";
import { Button, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, IconButton } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
function RowActions() {
  return (
    <DropdownMenu>
      <DropdownMenuTrigger
        render={
          <IconButton
            intent="outline"
            icon={<MoreHorizontal />}
            aria-label="Opportunity actions"
          />
        }
      />
      <DropdownMenuContent className="w-56">
        <DropdownMenuItem shortcut="mod+e">
          <Pencil /> Edit details
        </DropdownMenuItem>
        <DropdownMenuItem shortcut="mod+d">
          <Copy /> Duplicate
        </DropdownMenuItem>
        <DropdownMenuSub>
          <DropdownMenuSubTrigger>
            <Share2 /> Share
          </DropdownMenuSubTrigger>
          <DropdownMenuSubContent className="w-44">
            <DropdownMenuItem>Copy link</DropdownMenuItem>
            <DropdownMenuItem>Email a colleague</DropdownMenuItem>
          </DropdownMenuSubContent>
        </DropdownMenuSub>
        <DropdownMenuItem disabled>
          <Archive /> Archive
        </DropdownMenuItem>
        <DropdownMenuSeparator />
        <DropdownMenuItem destructive>
          <Trash2 /> Delete
        </DropdownMenuItem>
      </DropdownMenuContent>
    </DropdownMenu>
  );
}
```

### Actions

Icon and label rows, shortcuts as keys on the right, a submenu with a grey chevron, a disabled row in muted text, and Delete in the danger tone below a divider.

```tsx
<RowActions />
```

### Checkbox and radio rows

Rows that toggle or choose show a navy tick on the right, with no fill; the highlight stays grey for hover and keyboard. Labels name each group.

```tsx
<DropdownMenu>
  <DropdownMenuTrigger
    render={<Button intent="outline">View options</Button>}
  />
  <DropdownMenuContent className="w-56">
    <DropdownMenuGroup>
      <DropdownMenuLabel>Columns</DropdownMenuLabel>
      <DropdownMenuCheckboxItem value="stage" defaultChecked>
        Stage
      </DropdownMenuCheckboxItem>
      <DropdownMenuCheckboxItem value="owner" defaultChecked>
        Responsible
      </DropdownMenuCheckboxItem>
      <DropdownMenuCheckboxItem value="value">
        Value
      </DropdownMenuCheckboxItem>
    </DropdownMenuGroup>
    <DropdownMenuSeparator />
    <DropdownMenuGroup>
      <DropdownMenuLabel>Sort by</DropdownMenuLabel>
      <DropdownMenuRadioGroup defaultValue="updated">
        <DropdownMenuRadioItem value="updated">
          Last updated
        </DropdownMenuRadioItem>
        <DropdownMenuRadioItem value="created">
          Created
        </DropdownMenuRadioItem>
        <DropdownMenuRadioItem value="name">Name</DropdownMenuRadioItem>
      </DropdownMenuRadioGroup>
    </DropdownMenuGroup>
  </DropdownMenuContent>
</DropdownMenu>
```

## Props

DropdownMenu also takes ui-sdk's Menu options (open, defaultOpen, onOpenChange, onAction, controller). Items take value, label, closeOnSelect and onSelect; returning a Promise from onSelect keeps the row busy and the menu open until it settles.

### DropdownMenu

No props of its own.

### DropdownMenuContent

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
| `sideOffset` | `unknown` | `4` | The gap between it and what it opens from, in pixels. |

### DropdownMenuItem

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | An icon first, then the label: `<Trash2 /> Delete`. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### DropdownMenuCheckboxItem

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### DropdownMenuRadioItem

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### DropdownMenuLabel

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### DropdownMenuSeparator

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### DropdownMenuSubTrigger

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
