# Menu

Source: https://ecosphere.dev/docs/feedback/menu (Ecosphere 1.5). Install `vue-ecosphere` for Vue 3 or `react-ecosphere` for React 18.2+/19: same components, props, markup and stylesheet.

A popup list anchored to the control that opened it: actions, a checklist, a single choice with a tick, or a long checklist under a fixed footer.

`import { EcoMenu } from "vue-ecosphere"`

## Account menu

Actions close the menu. Arrow keys, Home and End move between entries; Escape closes and returns focus.

Vue (vue-ecosphere):

```vue
<EcoMenu v-model:open="open" :items="[
  { label: 'Profile', icon: 'user-3-line' },
  { label: 'Settings', icon: 'settings-3-line' },
  { label: 'Members', icon: 'team-line' },
  { label: 'Keyboard shortcuts', icon: 'keyboard-line' },
  { type: 'separator' },
  { label: 'Sign out', icon: 'logout-box-r-line' },
]" align="right" @select="(item) => …">
  <template #trigger="{ attrs }">
    <button class="avatar avatar--sm" type="button" aria-label="Account, Alex Jordan" v-bind="attrs">AJ</button>
  </template>
  <template #head>
    <div class="menu__who">…Alex Jordan · alex.jordan@example.com…</div>
  </template>
  <template #foot>
    <span class="menu__who-h">Northwind workspace</span>
    <button class="link link--ul" type="button">Switch</button>
  </template>
</EcoMenu>
```

React (react-ecosphere):

```tsx
const [open, setOpen] = useState(false);

<EcoMenu open={open} onOpenChange={setOpen} items={[
  { label: "Profile", icon: "user-3-line" },
  { label: "Settings", icon: "settings-3-line" },
  { label: "Members", icon: "team-line" },
  { label: "Keyboard shortcuts", icon: "keyboard-line" },
  { type: "separator" },
  { label: "Sign out", icon: "logout-box-r-line" },
]} align="right" onSelect={(item) => …}
  renderTrigger={({ attrs }) => (
    <button className="avatar avatar--sm" type="button" aria-label="Account, Alex Jordan" {...attrs}>AJ</button>
  )}
  head={<div className="menu__who">…Alex Jordan · alex.jordan@example.com…</div>}
  renderFoot={() => (
    <>
      <span className="menu__who-h">Northwind workspace</span>
      <button className="link link--ul" type="button">Switch</button>
    </>
  )}
/>
```

## Filter menu

A checklist toggles without closing, so several entries change in one visit.

Vue (vue-ecosphere):

```vue
<EcoMenu v-model:open="open" v-model:checked="checked" wide label="Filter requests" :items="[
  { type: 'checkbox', label: 'Starred', value: 'starred' },
  { type: 'checkbox', label: 'Awaiting review', value: 'awaiting' },
  …
]">
  <template #trigger="{ attrs }"><EcoButton icon="filter-3-line" v-bind="attrs">Filter</EcoButton></template>
</EcoMenu>
```

React (react-ecosphere):

```tsx
<EcoMenu open={open} onOpenChange={setOpen} checked={checked} onCheckedChange={setChecked} wide label="Filter requests" items={[
  { type: "checkbox", label: "Starred", value: "starred" },
  { type: "checkbox", label: "Awaiting review", value: "awaiting" },
  …
]}
  renderTrigger={({ attrs }) => <EcoButton icon="filter-3-line" {...attrs}>Filter</EcoButton>}
/>
```

## Range menu

A single choice marks the current value with a tick and closes on choosing.

Vue (vue-ecosphere):

```vue
<EcoMenu v-model:open="open" v-model:selected="range" :items="[
  { type: 'radio', label: 'Week', value: 'week' },
  { type: 'radio', label: 'Month', value: 'month' },
  { type: 'radio', label: 'All time', value: 'all' },
]">
  <template #trigger="{ attrs }"><EcoButton size="sm" icon-end="arrow-down-s-line" v-bind="attrs">Week</EcoButton></template>
</EcoMenu>
```

React (react-ecosphere):

```tsx
<EcoMenu open={open} onOpenChange={setOpen} selected={range} onSelectedChange={setRange} items={[
  { type: "radio", label: "Week", value: "week" },
  { type: "radio", label: "Month", value: "month" },
  { type: "radio", label: "All time", value: "all" },
]}
  renderTrigger={({ attrs }) => <EcoButton size="sm" iconEnd="arrow-down-s-line" {...attrs}>Week</EcoButton>}
/>
```

## Long checklist, fixed footer

A table's column chooser: the entries scroll, and Compact rows stays in reach underneath.

Vue (vue-ecosphere):

```vue
<EcoMenu v-model:open="open" v-model:checked="columns" scroll head="Columns" :items="columnItems">
  <template #trigger="{ attrs }">…</template>
  <template #foot>
    <!-- a setting that stays in reach while the list scrolls -->
  </template>
</EcoMenu>
```

React (react-ecosphere):

```tsx
<EcoMenu open={open} onOpenChange={setOpen} checked={columns} onCheckedChange={setColumns} scroll head="Columns" items={columnItems}
  renderTrigger={({ attrs }) => …}
  renderFoot={() => (
    <>{/* a setting that stays in reach while the list scrolls */}</>
  )}
/>
```

## API

Vue (vue-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `EcoMenuItem[]` | — | { type?: 'item' \| 'checkbox' \| 'radio' \| 'separator' \| 'head', label, value?, icon?, danger?, disabled? }. Or write menu__opt buttons in the default slot. |
| `v-model:open` | `boolean` | false | Open state (menu.is-open). Escape and an outside click close it; Escape returns focus to the trigger. |
| `v-model:checked` | `(string \| number)[]` | [] | Values of the ticked checkbox entries. Checklist entries toggle without closing. |
| `v-model:selected` | `string \| number` | — | Value of the chosen radio entry (tick); choosing closes the menu. |
| `align` | `"left" \| "right"` | "left" | right → menu--right, aligned to the trigger's right edge. A single-choice menu (radio items) is a rangemenu and always opens from the right edge. |
| `wide` | `boolean` | false | menu--wide (320px). |
| `scroll` | `boolean` | false | menu--scroll: entries scroll in menu__scroll under a fixed menu__foot. |
| `head` | `string` | — | Uppercase caption (menu__head). The #head slot replaces it (e.g. menu__who). |
| `#trigger` | `slot { attrs, open, toggle }` | — | Bind attrs to your button: aria-haspopup, aria-expanded, aria-controls, click and ArrowDown/ArrowUp to open. |
| `#foot` | `slot { close }` | — | menu__foot (split layout unless scroll). |
| `@select` | `(item) => void` | — | An entry was chosen. |

React (react-ecosphere):

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `EcoMenuItem[]` | — | { type?: 'item' \| 'checkbox' \| 'radio' \| 'separator' \| 'head', label, value?, icon?, danger?, disabled? }. Or write menu__opt buttons as children (a node, or a function of { close }). |
| `open / onOpenChange` | `boolean` | false | Open state (menu.is-open). Escape and an outside click close it; Escape returns focus to the trigger. Or defaultOpen; a ref exposes show(), close() and toggle(). |
| `checked / onCheckedChange` | `(string \| number)[]` | [] | Values of the ticked checkbox entries. Checklist entries toggle without closing. |
| `selected / onSelectedChange` | `string \| number` | — | Value of the chosen radio entry (tick); choosing closes the menu. |
| `align` | `"left" \| "right"` | "left" | right → menu--right, aligned to the trigger's right edge. A single-choice menu (radio items) is a rangemenu and always opens from the right edge. |
| `wide` | `boolean` | false | menu--wide (320px). |
| `scroll` | `boolean` | false | menu--scroll: entries scroll in menu__scroll under a fixed menu__foot. |
| `head` | `ReactNode` | — | Uppercase caption (menu__head). A node instead of text replaces it (e.g. menu__who). |
| `renderTrigger` | `(scope: { attrs, open, toggle }) => ReactNode` | — | Spread attrs on your button: id, aria-haspopup, aria-expanded, aria-controls, onClick and ArrowDown/ArrowUp to open. |
| `renderFoot` | `(scope: { close }) => ReactNode` | — | menu__foot (split layout unless scroll). |
| `onSelect` | `(item) => void` | — | An entry was chosen. |
