# Context menu

Contextual actions opened by right-click, long press or keyboard.

## Web 0.2.0

### Usage

Supply a focusable trigger, a menu label and actions with stable ids. Each onSelect receives its action id; ordinary trigger clicks remain available.

### Accessibility

Right-click or long-press the trigger, or focus it and press Shift+F10 or the Context Menu key. Arrows navigate; Enter selects; Escape dismisses and returns focus. Keep essential actions available through a visible control too.

### When to use

Use for secondary actions on an object. Use Menu for a visible action button and Select for a form value. Empty or disabled menus stay closed.

### Install

Add this registry to your project's components.json once, before the first install. Keep your existing settings and other registries.

```json
{
  "registries": {
    "@maeso": "http://127.0.0.1:4321/r/{name}.json"
  }
}
```

Then install the registry's default theme once, and import its sheet in the CSS entry that imports Tailwind. It paints every item from this registry.

```sh
npx shadcn@latest add @maeso/maeso
```

```css
@import "./styles/theme.web.css";
```

```sh
npx shadcn@latest add @maeso/context-menu
```

### Props

#### ContextMenu

| Prop | Type | Required | Description |
| --- | --- | --- | --- |
| items | readonly ContextMenuAction[] | yes |  |
| label | string | yes | The accessible name of the menu. |
| trigger | ReactElement<unknown, string \| JSXElementConstructor<any>> | yes | A focusable element; keep its ordinary click action available. |
| disabled | boolean \| undefined | no |  |

### Proof

#### Contrast

measured on 0.2.0

| State | Foreground | Background | Ratio | Floor |
| --- | --- | --- | --- | --- |
| default | rgb(7 21 34) | rgb(239 239 239) | 16.03 | AA 4.5 |
| default (dark) | rgb(248 245 240) | rgb(107 107 107) | 4.90 | AA 4.5 |

#### Keyboard

measured on 0.2.0

| Key | Action |
| --- | --- |
| Shift+F10 | Open menu and focus its first item |
| ArrowDown | Focus the next item |
| ArrowUp | Focus the previous item |
| End | Focus the last item |
| Home | Focus the first item |
| Enter | Choose the focused item and return focus to the trigger |
| Escape | Dismiss the menu and return focus to the trigger |

#### Size

54392 gzip bytes · measured on 0.2.0

### Motion

The menu enters beside its trigger.

Configured duration: 200 ms

Reduced motion: none

#### Motion timing

Observed duration: 200 ms · measured on 0.2.0

#### Reduced motion

passed · measured on 0.2.0

### Example

```tsx
import { ContextMenu } from "@/components/ui/_kit/overlay/context-menu/ContextMenu";

export default function Example() {
return <ContextMenu label="Document actions" trigger={<button type="button">Document</button>} items={[{ id: "open", label: "Open", onSelect: () => {} }]} />;
}

```

### Preview · 0.2.0

not on native yet
