# Dropdown menu

A list of actions that opens from a button.

This is the HTML to build it with `dex.css`, for work outside the Dex codebase. Read https://brand.meetdex.ai/design.md first: it says how to set up a page and how to use the stylesheet. The page at https://brand.meetdex.ai/components/dropdown-menu shows the Dex app's own React component, which only works inside the Dex codebase.

## HTML

A `dex-menu` of `dex-menu-item`s inside a `dex-popover-anchor`, which places it 4px under its trigger. Show and hide it with `hidden`:

```html
<div class="dex-popover-anchor">
  <button type="button" class="dex-button dex-button--outline" aria-haspopup="menu" aria-expanded="false" aria-controls="role-actions">Actions</button>
  <div class="dex-menu" id="role-actions" role="menu" hidden>
    <button class="dex-menu-item" role="menuitem">Share role</button>
    <button class="dex-menu-item" role="menuitem">Save for later</button>
    <button class="dex-menu-item" role="menuitem" aria-disabled="true">Ask a question</button>
    <hr role="separator" />
    <button class="dex-menu-item" role="menuitem" style="color: var(--dex-destructive)">Withdraw</button>
  </div>
</div>
```

Open and close it with the popover's script (https://brand.meetdex.ai/components/popover.md), with `anchor.querySelector('#role-actions')` in place of `.dex-popover`, and close it when an item is chosen.

- **Disabled item**: `aria-disabled="true"` dims it to 50%.
- **Shortcut**: a `dex-menu-detail` at the end of the row, muted (`<span class="dex-menu-detail">⌘S</span>`).
- **Checkbox items**: `role="menuitemcheckbox"` with `aria-checked="true"` or `"false"`. A checked item gets the tick at the end.
- **Radio items**: `role="menuitemradio"` in a `role="group"`, with `aria-checked="true"` on the chosen one.
- **Icons**: a 16px Lucide `<svg>` before the label.
- **Separators**: an `<hr>` in the menu, which `dex.css` runs edge to edge.
- **Group labels and submenus**: `dex.css` has no class for them. A group label is a `<div class="dex-small dex-muted" style="padding: 0.375rem 0.625rem">` inside a `role="group"` named by it. Avoid submenus in a prototype; put the choices in the menu itself.

## Rules

- The trigger is a button. An icon-only trigger needs an `aria-label`.
- Choosing an item closes the menu, and that includes ticking a checkbox item or picking a radio item.
- The arrow keys move between items and stop at the first and last; they don't wrap round.
- A destructive item goes last, after a separator.
- Near the edge of the screen, open it on the other side or line it up with the trigger's end (`right: 0; left: auto`).
