# Menu

A popover menu of actions, opened by click or hover.

Source: https://www.zazz.sh/api/primitives/menu/

## Installation

```bash
pnpm dlx zazz-ui add menu
```

Also adds `fields`, `kbd`, `button`, `popover`, which it depends on.

Run `zazz-ui init` first if the project has no `zazz/` folder yet.

## Examples

### Default

```html
<div
  style="
    --display: flex;
    --gap: 4;
  "
>
  <ui-menu>
    <button data-ui="button" type="button" popovertarget="menu-example-1">Bottom / start</button>
    <div
      id="menu-example-1"
      data-menu-slot="popover"
      data-popover-side="bottom"
      data-popover-align="start"
      popover="auto"
    >
      <menu>
        <li
          style="
            --display: inline-flex;
            --p: 2;
            --font-size: var(--font-size-eyebrow);
            --font-weight: strong;
            --leading: var(--leading-eyebrow);
            --tracking: var(--tracking-eyebrow);
            --text-transform: uppercase;
            --text: var(--color-muted-foreground);
          "
        >
          Group 1
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 1</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 2</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 3</a
          >
        </li>
        <hr data-ui="separator" style="--my: 2" />
        <li
          style="
            --display: inline-flex;
            --p: 2;
            --font-size: var(--font-size-eyebrow);
            --font-weight: strong;
            --leading: var(--leading-eyebrow);
            --tracking: var(--tracking-eyebrow);
            --text-transform: uppercase;
            --text: var(--color-muted-foreground);
          "
        >
          Group 2
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 4</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 5</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 6</a
          >
        </li>
      </menu>
    </div>
  </ui-menu>

  <ui-menu>
    <button data-ui="button" type="button" popovertarget="menu-example-2">Bottom / center</button>
    <div
      id="menu-example-2"
      data-menu-slot="popover"
      data-popover-side="bottom"
      data-popover-align="center"
      popover="auto"
    >
      <menu>
        <li
          style="
            --display: inline-flex;
            --p: 2;
            --font-size: var(--font-size-eyebrow);
            --font-weight: strong;
            --leading: var(--leading-eyebrow);
            --tracking: var(--tracking-eyebrow);
            --text-transform: uppercase;
            --text: var(--color-muted-foreground);
          "
        >
          Group 1
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 1</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 2</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 3</a
          >
        </li>
        <hr data-ui="separator" style="--my: 2" />
        <li
          style="
            --display: inline-flex;
            --p: 2;
            --font-size: var(--font-size-eyebrow);
            --font-weight: strong;
            --leading: var(--leading-eyebrow);
            --tracking: var(--tracking-eyebrow);
            --text-transform: uppercase;
            --text: var(--color-muted-foreground);
          "
        >
          Group 2
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 4</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 5</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 6</a
          >
        </li>
      </menu>
    </div>
  </ui-menu>

  <ui-menu>
    <button data-ui="button" type="button" popovertarget="menu-example-3">Bottom / end</button>
    <div
      id="menu-example-3"
      data-menu-slot="popover"
      data-popover-side="bottom"
      data-popover-align="end"
      popover="auto"
    >
      <menu>
        <li
          style="
            --display: inline-flex;
            --p: 2;
            --font-size: var(--font-size-eyebrow);
            --font-weight: strong;
            --leading: var(--leading-eyebrow);
            --tracking: var(--tracking-eyebrow);
            --text-transform: uppercase;
            --text: var(--color-muted-foreground);
          "
        >
          Group 1
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 1</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 2</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 3</a
          >
        </li>
        <hr data-ui="separator" style="--my: 2" />
        <li
          style="
            --display: inline-flex;
            --p: 2;
            --font-size: var(--font-size-eyebrow);
            --font-weight: strong;
            --leading: var(--leading-eyebrow);
            --tracking: var(--tracking-eyebrow);
            --text-transform: uppercase;
            --text: var(--color-muted-foreground);
          "
        >
          Group 2
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 4</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 5</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Link 6</a
          >
        </li>
      </menu>
    </div>
  </ui-menu>
</div>
```

### Interest

```html
<div
  style="
    --display: flex;
    --gap: 4;
  "
>
  <ui-menu>
    <button
      data-ui="button"
      type="button"
      popovertarget="menu-interest-example-1"
      interestfor="menu-interest-example-1"
    >
      Hover or click
    </button>
    <div
      id="menu-interest-example-1"
      data-menu-slot="popover"
      data-popover-side="bottom"
      data-popover-align="start"
      popover="auto"
    >
      <menu>
        <li
          style="
            --display: inline-flex;
            --p: 2;
            --font-size: var(--font-size-eyebrow);
            --font-weight: strong;
            --leading: var(--leading-eyebrow);
            --tracking: var(--tracking-eyebrow);
            --text-transform: uppercase;
            --text: var(--color-muted-foreground);
          "
        >
          Account
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Profile</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Settings</a
          >
        </li>
        <hr data-ui="separator" style="--my: 2" />
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Sign out</a
          >
        </li>
      </menu>
    </div>
  </ui-menu>

  <ui-menu>
    <button
      data-ui="button"
      type="button"
      data-button-variant="outline"
      popovertarget="menu-interest-example-2"
      interestfor="menu-interest-example-2"
    >
      Resources
    </button>
    <div
      id="menu-interest-example-2"
      data-menu-slot="popover"
      data-popover-side="bottom"
      data-popover-align="start"
      popover="auto"
    >
      <menu>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Documentation</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Changelog</a
          >
        </li>
        <li>
          <a href="#" data-ui="button" data-button-variant="ghost" style="--justify: start"
            >Support</a
          >
        </li>
      </menu>
    </div>
  </ui-menu>
</div>
```

## Behavior

`primitives/menu/menu.js`

`<ui-menu>`: HTML web component for keyboard-enhanced menus.
Light-DOM custom element that augments the CSS-only menu
pattern (trigger + anchored `[data-menu-slot~="popover"]` panel) with
arrow-key navigation. The attribute form `[data-ui~="menu"]` stays fully functional
without JavaScript: the Popover API provides open/close, light dismiss,
and focus return on its own.

Keyboard behavior:
- ArrowDown / ArrowUp on the closed trigger open the panel and focus the
  first / last item.
- ArrowDown / ArrowUp inside the open panel move focus between items,
  wrapping around and skipping disabled items.
- Home / End jump to the first / last item.
- Escape and light dismiss are native Popover API behavior (no code here).

The menu keeps the honest disclosure posture: items are plain links and
buttons, and no `role="menu"` is claimed. Add the full ARIA menu contract
yourself only if every item is an action and you implement the rest of the
pattern (typeahead, close-on-activate).

## Attributes

| Attribute | Kind | Values |
| --- | --- | --- |
| `data-ui="menu"` | identity | free value |
| `<ui-menu>` | tag | free value |
| `data-menu-slot` | slot | `popover` |

Requires: popover, button.

## Hooks

| Hook | Default | State |
| --- | --- | --- |
| `--ui-menu-button-corner-shape` | `var(--radius-corner-shape)` | — |
| `--ui-menu-button-radius` | `var(--radius-sm)` | — |
| `--ui-menu-gap` | `var(--ui-field-option-gap)` | — |
| `--ui-menu-min-w` | `calc(var(--spacing) * 52)` | — |
| `--ui-menu-shadow` | `var(--shadow-sm)` | — |
