# More menu

## Usage

`MoreMenu` is an overflow menu behind a `⋯` trigger. It holds the actions that do not need to stay visible: secondary actions in a table row, a card header, or a toolbar. The trigger is an icon-only button; everything it offers lives in the menu it opens.

The menu's content is described by an `items` array. A plain entry is one action, `type: 'divider'` is a hairline between groups, and `type: 'section'` is a titled group:

```vue
<script setup lang="ts">
import { MoreMenu } from '@astryx-vue/core/MoreMenu'

const items = [
  { label: 'Rename', onClick: () => rename() },
  { label: 'Duplicate', onClick: () => duplicate() },
  { type: 'divider' },
  { label: 'Move to trash', variant: 'destructive', onClick: () => remove() },
]
</script>

<template>
  <MoreMenu :items="items" label="File actions" />
</template>
```

The trigger is icon-only, so `label` is its accessible name, the name of the menu itself, and the text of its tooltip. When `label` is omitted it follows the active locale: `More options` in English, 「更多选项」 in Chinese. When the menu holds the actions of one specific thing, a more concrete phrase such as "Project actions" reads better. Use the `icon` slot to replace the three-dot artwork.

Where focus lands when the menu opens depends on how it was opened. A keyboard open (`Enter`, `Space`, `ArrowDown`, or `ArrowUp` on the trigger) lands on the first or the last row; a pointer open puts focus on the menu container and pre-highlights nothing, so no row reads as already selected. Once open, `ArrowDown` and `ArrowUp` move between rows and wrap at both ends, `Home` and `End` jump to the ends, typing a letter jumps to the next row starting with it, `Enter` and `Space` run the focused row, `Escape` closes the menu and returns focus to the trigger, and `Tab` closes the menu and lets the browser move on from the trigger. Disabled rows are skipped and stay out of the keyboard path.

Mouse and touch behave differently on purpose. With a mouse, the highlight follows the pointer while it is held and the release decides which row acts; releasing outside the menu dismisses it. With a finger, a release off the menu leaves it open, because the highlight is following the finger — the gesture ends when a row is picked, the trigger is tapped, or `Escape` is pressed. The `placement` and `alignment` props place the anchored menu beside the trigger and flip it when there is no room; an overflow menu usually wants `alignment="end"`, so the menu lines up with the trigger's trailing edge.

`presentation` decides the shape the actions arrive in. `popover` (the default) is the anchored surface; `bottom-sheet` is a modal panel at the bottom of the screen, sized for a thumb; `adaptive` keeps the anchored menu on pointer-driven layouts and uses the bottom panel at 768px and below when the primary pointer is coarse. Inside the bottom panel a submenu does not open a second panel: the view is replaced, its title becomes the submenu's own label, a back button appears, and `Escape` leaves the submenu before it closes the panel.

The open state can belong to the component or to you. Pass `isMenuOpen` to control it, usually with `v-model:isMenuOpen`; `openChange` fires every time an open or close is requested.

### Anatomy

- **Trigger button**: Icon-only Button that provides the visible overflow-menu entry point.
- **Icon-resolved trigger icon**: Default semantic three-dot artwork resolved from the active Icon registry.
- **Caller-rendered trigger content**: Arbitrary slot content supplied directly as the trigger icon override.
- **Menu surface**: DropdownMenu panel that also carries MoreMenu’s current public target.
- **Pointer action row**: Action or nested-action trigger row rendered by DropdownMenu in the anchored presentation.
- **Touch action row**: ListItem button rendered by DropdownMenu in the BottomSheet presentation.

## Best practices

| Guidance | Practice |
| --- | --- |
| Do | Keep it for secondary actions. A primary action belongs in the open, where people can see it; hiding it in a menu makes it hard to find. |
| Do | With many entries, group them with dividers or sections — and keep destructive actions last and marked `variant="destructive"`. |
| Do | Give similar rows a `description`, so near neighbours such as "Export" and "Publish" can be told apart at a glance. |
| Do | Use `alignment="end"` when the trigger sits at the end of a table row or toolbar, so the menu lines up with the trigger instead of covering the content. |
| Do | Use `presentation="adaptive"` for interfaces used mostly on phones, where a thumb reaches the actions on a bottom panel. |
| Avoid | Vague names, such as a "More" entry inside a "More" menu. The trigger needs a `label` that says what the menu is for. |
| Avoid | Piling a dozen actions into one menu. Past a screenful, the reader has to open, scroll, and pick — worse than showing the actions directly. |
| Avoid | Keying data or navigation off whether the menu happens to be open. A menu is a temporary surface; its state belongs in your own data. |

## Examples

### Bottom sheet

A visible overflow trigger that opens actions in a BottomSheet. Use this presentation for short action sets on compact touch surfaces.

```vue
<script setup lang="ts">
import type { MoreMenuOption } from '@astryx-vue/core/MoreMenu'
import { MoreMenu } from '@astryx-vue/core/MoreMenu'

const items: MoreMenuOption[] = [
  { label: 'Rename project', description: 'Update the project title.', icon: 'i-heroicons-pencil', onClick: () => {} },
  { label: 'Duplicate project', description: 'Create a copy in this workspace.', icon: 'i-heroicons-document-duplicate', onClick: () => {} },
  { label: 'Share project', description: 'Invite people to collaborate.', icon: 'i-heroicons-share', onClick: () => {} },
  { label: 'Delete project', description: 'Move this project to the trash.', icon: 'i-heroicons-trash', variant: 'destructive', onClick: () => {} },
]
</script>

<template>
  <div style="display: flex; align-items: center; justify-content: space-between; gap: 16px; width: min(100%, 360px); padding: 16px; border: 1px solid #d1d5db; border-radius: 12px;">
    <div style="display: flex; flex-direction: column; gap: 4px;">
      <strong>Quarterly plan</strong>
      <span>Updated a few minutes ago</span>
    </div>
    <MoreMenu presentation="bottom-sheet" label="Project actions" :items="items" />
  </div>
</template>
```

### Default

Basic three-dot overflow menu with simple text-only action items.

```vue
<script setup lang="ts">
import type { MoreMenuOption } from '@astryx-vue/core/MoreMenu'
import { MoreMenu } from '@astryx-vue/core/MoreMenu'

const items: MoreMenuOption[] = [
  { label: 'Edit', onClick: () => {} },
  { label: 'Duplicate', onClick: () => {} },
  { label: 'Delete', onClick: () => {} },
]
</script>

<template>
  <MoreMenu :items="items" />
</template>
```

### With dividers

A three-dot menu with a divider separating destructive actions from safe ones.

```vue
<script setup lang="ts">
import type { MoreMenuOption } from '@astryx-vue/core/MoreMenu'
import { MoreMenu } from '@astryx-vue/core/MoreMenu'

const items: MoreMenuOption[] = [
  { label: 'Edit', icon: 'i-heroicons-pencil', onClick: () => {} },
  { label: 'Duplicate', icon: 'i-heroicons-document-duplicate', onClick: () => {} },
  { type: 'divider' },
  { label: 'Delete', icon: 'i-heroicons-trash', onClick: () => {} },
]
</script>

<template>
  <MoreMenu variant="secondary" :items="items" />
</template>
```

### With sections

A three-dot menu with actions organized into labeled groups.

```vue
<script setup lang="ts">
import type { MoreMenuOption } from '@astryx-vue/core/MoreMenu'
import { MoreMenu } from '@astryx-vue/core/MoreMenu'

const items: MoreMenuOption[] = [
  {
    type: 'section',
    title: 'Actions',
    items: [
      { label: 'Edit', icon: 'i-heroicons-pencil', onClick: () => {} },
      { label: 'Duplicate', icon: 'i-heroicons-document-duplicate', onClick: () => {} },
    ],
  },
  {
    type: 'section',
    title: 'Danger zone',
    items: [{ label: 'Delete', icon: 'i-heroicons-trash', onClick: () => {} }],
  },
]
</script>

<template>
  <MoreMenu variant="secondary" label="Document actions" :items="items" />
</template>
```

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `items` | `MoreMenuOption[]` | - | What the menu holds: actions (`MoreMenuItem`), hairlines (`{ type: 'divider' }`), and groups (`{ type: 'section', title, items }`). Required. |
| `label` | `string` | the active locale (`More options` in English) | The trigger's accessible name, which is also the name of the menu itself and the text of its tooltip. |
| `variant` | `ButtonVariant` | `'ghost'` | Visual variant of the trigger button: primary, secondary, ghost, or destructive. |
| `size` | `ButtonSize` | `'md'` | Size of the trigger button: sm, md, or lg. The density of every menu row follows it. |
| `isDisabled` | `boolean` | `false` | Whether the trigger is disabled. A disabled trigger is dimmed, announces itself as disabled, and opens nothing from a click or the keyboard. |
| `placement` | `'above' \| 'below' \| 'start' \| 'end'` | `'below'` | Where the anchored surface sits relative to the trigger. The direction is logical: start and end resolve against the menu's own direction, so RTL mirrors them. The surface flips when there is no room. |
| `alignment` | `'start' \| 'center' \| 'end'` | `'start'` | Alignment along the placement axis. An overflow menu usually wants end, so the surface lines up with the trigger's trailing edge. |
| `presentation` | `'popover' \| 'bottom-sheet' \| 'adaptive'` | `'popover'` | Shape the actions arrive in. popover anchors the surface to the trigger; bottom-sheet is a modal panel at the bottom of the screen; adaptive uses the bottom panel at 768px and below when the primary pointer is coarse, and the anchored surface otherwise. |
| `isMenuOpen` | `boolean` | - | Controlled open state, meant for `v-model:isMenuOpen`. Leave it unbound to let the component own its state. |
| `isInline` | `boolean` | `false` | Renders the surface in place instead of moving it to the top of the document. It then flows with the page and is not positioned against the viewport. Intended for documentation previews and for surfaces that must not escape their container. |

### MoreMenuItem

An action entry in `items` carries:

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `string` | - | The row's primary text. Required. |
| `id` | `string` | - | Stable identity of the row within its level. Omit it and the row is matched by position; set it when `items` can reorder, filter, or grow, so a row keeps its DOM node — and its keyboard focus — as the array changes. |
| `icon` | `string \| Component` | - | Icon shown before the label: a CSS icon class (an UnoCSS class such as `i-carbon-copy`, or one of your own), or a component that draws the SVG. astryx-vue ships no icons. |
| `description` | `string` | - | A supporting line below the label, for telling near neighbours apart. |
| `isDisabled` | `boolean` | `false` | Whether the row is unavailable. A disabled row is dimmed, announces itself as disabled, and is skipped by the arrow keys and by type-ahead. |
| `variant` | `'default' \| 'destructive'` | `'default'` | destructive paints the label, description, and icon in the error color for dangerous actions such as deletion. |
| `href` | `string` | - | Address the row navigates to. With it the row is a real link, so a modified click and a middle click keep their browser meaning, such as opening a new tab. |
| `target` | `'_blank' \| '_self'` | - | Where the link opens. Only used with `href`. |
| `rel` | `string` | - | Link relationship tokens. `noopener noreferrer` is added when `target` is `_blank`. |
| `endContent` | `string` | - | Trailing content of the row, such as a shortcut hint. |
| `hasCloseOnSelect` | `boolean` | `true` | Whether activating the row closes the menu. Set it to false for an action that reports its result on the row itself, such as a copy row that swaps to "Copied". |
| `items` | `MoreMenuOption[]` | - | Nested entries. With them the row becomes a submenu entry: it opens a flyout on a pointer layout and shows its own view in the bottom panel. |
| `onClick` | `(event: MouseEvent) => void` | - | The row's action. On a link row it runs before the browser navigates, and is skipped for a modified click, which belongs to the browser. |

## Events

| Name | Payload | Description |
| --- | --- | --- |
| `openChange` | `(isOpen: boolean) => void` | Fired whenever an open or close is requested. In uncontrolled usage it reports the change; in controlled usage it is the request to update the bound state. |
| `update:isMenuOpen` | `(isOpen: boolean) => void` | The update event of `v-model:isMenuOpen` in controlled usage. |

## Slots

| Name | Description |
| --- | --- |
| `icon` | Artwork of the trigger, replacing the default three-dot icon. The trigger stays icon-only and takes its accessible name from `label`. |

## Exposed

| Name | Type | Description |
| --- | --- | --- |
| `element` | `HTMLElement \| null` | The trigger button element. |
| `focus` | `(options?: FocusOptions) => void` | Moves focus onto the trigger button. |
| `blur` | `() => void` | Removes focus from the trigger button. |

## Native attributes

The root element is a `<span>`, and the trigger button is the `<button>` inside it.

Attributes passed to the component — <code>class</code>, <code>style</code>, <code>data-*</code>, and the rest — fall through to the root element. The trigger button takes its accessible name from <code>label</code>, and its <code>aria-expanded</code>, <code>aria-haspopup</code>, and <code>aria-controls</code> are maintained by the component from the open state and the presentation.

While the menu is open its surface moves to the end of the document, under `<body>`, and is presented as a floating layer. Set <code>is-inline</code> to keep it where it is.
