---
title: ContextMenu
description: Open item-specific actions at a context interaction point.
package: moraine
version: 0.11.0
repository: https://github.com/subframe7536/moraine
---

# ContextMenu

> Open item-specific actions at a context interaction point.

## Anatomy

```text
ContextMenu [component; no DOM]
├── ContextMenu.Trigger [part; slot=trigger]
├── overlay [slot]
└── positioner [internal]
    └── ContextMenu.Content [part; slot=content]
        ├── group [slot]
        │   ├── groupLabel [slot]
        │   └── item [slot]
        ├── item [slot]
        │   ├── itemLeading [slot]
        │   ├── itemWrapper [slot]
        │   │   ├── itemLabel [slot]
        │   │   └── itemDescription [slot]
        │   └── itemTrailing [slot]
        │       ├── itemKbds [slot]
        │       ├── itemIndicator [slot]
        │       └── itemSubIndicator [slot]
        └── separator [slot]
```

Content is portaled; grouped items use the same item subtree as ungrouped items.

## Usage

Use ContextMenu for actions tied to a specific surface or item at the pointer location. Use
[DropdownMenu](https://moraine.subf.dev/components/dropdown-menu.md) when the same actions open from a visible trigger. Use
[Popover](https://moraine.subf.dev/components/popover.md) when the content is not a list of commands. Use
[Dialog](https://moraine.subf.dev/components/dialog.md) when the user must complete or confirm a modal task. Keep essential
actions reachable through another visible path.

```tsx
import { ContextMenu } from 'moraine'

export function Example() {
  return (
    <ContextMenu>
      <ContextMenu.Trigger>Right-click here</ContextMenu.Trigger>
      <ContextMenu.Content items={[{ label: 'Copy' }]} />
    </ContextMenu>
  )
}
```

### Triggering the menu

Wrap the target with `ContextMenu.Trigger`. The menu opens at the pointer on right-click, or at the
center of the trigger when opened from the keyboard. A touch or pen long press (700 ms) also opens it.
The trigger renders a `div`; pass `as` to render another element. With `disabled` on the root, the
native browser menu shows instead.

```tsx
<ContextMenu>
  <ContextMenu.Trigger as="div" class="flex h-32 items-center justify-center">
    Right-click or long-press inside this area
  </ContextMenu.Trigger>
  <ContextMenu.Content
    items={[
      { label: 'Back', icon: 'i-lucide:arrow-left' },
      { label: 'Forward', icon: 'i-lucide:arrow-right', disabled: true },
      { label: 'Reload', icon: 'i-lucide:rotate-cw' },
    ]}
  />
</ContextMenu>
```

### Item models

The `items` array describes the whole menu. An item has `type` `'item'` (the default), `'checkbox'`,
`'radio-group'`, `'group'`, or `'separator'`; an item with `children` opens a submenu. Items accept
`icon`, `description`, `kbds`, `disabled`, and `variant: 'danger'`. `kbds` only displays keycaps and
does not register a shortcut. An entry that is an array of items forms its own group, and the menu
draws a separator between groups.

Checkbox and radio state is controlled with `checked` / `onCheckedChange` and with `value` /
`onValueChange` on the `radio-group` (not on each radio). Omit them to let the item manage its own
state, starting from `defaultChecked` or `defaultValue`. Selecting a checkbox or radio keeps the menu
open; selecting a regular item runs `onSelect` and closes it.

A parent item with `children` can take `open` and `onOpenChange` to control its submenu.
`onOpenChange` reports every open or close request from pointer, keyboard, or click interaction. With
a controlled `open`, the submenu stays at the prop value until you update it.

```tsx
<ContextMenu.Content
  items={[
    {
      type: 'checkbox',
      label: 'Pin item',
      checked: pinned(),
      onCheckedChange: setPinned,
    },
    { type: 'separator' },
    {
      type: 'radio-group',
      value: priority(),
      onValueChange: setPriority,
      items: [{ type: 'radio', label: 'High priority', value: 'high' }],
    },
  ]}
/>
```

`ContextMenu.Content` also takes `headerRender` and `footerRender` to add a header (such as the
target's metadata) or a footer around the item groups, in the root menu and in every submenu. Both
receive `{ sub }`. `itemRender` replaces the inner content of every item row; the row keeps its role,
keyboard handling, and selection.

### Dismissal and scrolling

Escape and outside presses close the menu. Set `closeOnEscape` or `closeOnOutsideClick` to `false` to
block them, and use `onClosePrevented` to react to the blocked attempt. While the menu is open, body
scroll is locked and an overlay renders behind the content; set `preventScroll` to `false` to keep the
page scrollable. Set `modal` to hide outside content from assistive technology while the menu is open.

### Keyboard interaction

| Key                                             | Description                                                               |
| ----------------------------------------------- | ------------------------------------------------------------------------- |
| <kbd>Shift + F10</kbd> / <kbd>ContextMenu</kbd> | Toggles the menu from the focused trigger.                                |
| <kbd>ArrowDown</kbd> / <kbd>ArrowUp</kbd>       | Moves focus to the next or previous item.                                 |
| <kbd>Home</kbd> / <kbd>End</kbd>                | Moves focus to the first or last item.                                    |
| Printable characters                            | Moves focus to the next item whose text starts with the typed characters. |
| <kbd>ArrowRight</kbd>                           | Opens the submenu of the focused item.                                    |
| <kbd>ArrowLeft</kbd>                            | Closes the current submenu and returns to its parent item.                |
| <kbd>Enter</kbd> / <kbd>Space</kbd>             | Activates the focused item, or opens its submenu.                         |
| <kbd>Escape</kbd>                               | Closes the current menu layer and restores focus.                         |
| <kbd>Tab</kbd>                                  | Closes the menu.                                                          |

## Examples

### Open page actions on a selected surface

Right-click or long-press the dashed region. Forward stays disabled in this example.

```tsx
import { ContextMenu } from 'moraine'
import type { ContextMenuT } from 'moraine'

const MENU_ITEMS = [
  { label: 'Back', icon: 'i-lucide:arrow-left' },
  { label: 'Forward', icon: 'i-lucide:arrow-right', disabled: true },
  { label: 'Reload', icon: 'i-lucide:rotate-cw' },
] satisfies ContextMenuT.Item[]

export function TriggerUsage() {
  return (
    <div class="max-w-md w-full">
      <ContextMenu>
        <ContextMenu.Trigger
          as="div"
          class="text-xs text-muted-foreground b-2 b-border rounded-xl b-dashed flex h-32 w-full select-none items-center justify-center"
        >
          Right-click or long-press inside this area
        </ContextMenu.Trigger>
        <ContextMenu.Content items={MENU_ITEMS} />
      </ContextMenu>
    </div>
  )
}
```

### Copy, rename, or delete a file

Describe grouped actions in the item model, including a danger-variant delete.

```tsx
import { ContextMenu } from 'moraine'

export function ItemsUsage() {
  return (
    <div class="max-w-md w-full">
      <ContextMenu>
        <ContextMenu.Trigger
          as="div"
          class="text-xs text-muted-foreground b-1 b-border rounded-xl flex h-28 w-full select-none items-center justify-center"
        >
          Right-click to view item model actions
        </ContextMenu.Trigger>
        <ContextMenu.Content
          items={[
            {
              label: 'Actions',
              children: [
                { label: 'Copy path', icon: 'i-lucide:copy' },
                { label: 'Rename file', icon: 'i-lucide:edit-2' },
                { label: 'Delete', icon: 'i-lucide:trash-2', variant: 'danger' },
              ],
            },
          ]}
        />
      </ContextMenu>
    </div>
  )
}
```

### Manage a project file

Move a file between folders, add it to favorites, or move it to the trash and undo. These actions
update local example state; permission-dependent actions remain disabled.

```tsx
import { Button, ContextMenu, Icon } from 'moraine'
import type { ContextMenuT } from 'moraine'
import { createMemo, createSignal, Show } from 'solid-js'

export function FileActions() {
  const [folder, setFolder] = createSignal('Projects')
  const [favorite, setFavorite] = createSignal(false)
  const [deleted, setDeleted] = createSignal(false)
  const [status, setStatus] = createSignal('Right click the file, long press, or use Shift + F10.')
  const items = createMemo<ContextMenuT.Item[]>(() => [
    {
      type: 'group',
      label: 'Project brief.pdf',
      children: [
        {
          label: 'Open preview',
          icon: 'i-lucide:eye',
          onSelect: () => setStatus('Preview ready: Project brief.pdf · 4 pages · 240 KB'),
        },
        {
          type: 'checkbox',
          label: 'Add to favorites',
          checked: favorite(),
          onCheckedChange: (checked: boolean) => {
            setFavorite(checked)
            setStatus(checked ? 'Added to favorites.' : 'Removed from favorites.')
          },
        },
      ],
    },
    { type: 'separator' },
    {
      label: 'Move to',
      icon: 'i-lucide:folder-input',
      children: ['Projects', 'Shared', 'Archive'].map((destination) => ({
        label: destination,
        icon: 'i-lucide:folder',
        disabled: folder() === destination,
        onSelect: () => {
          setFolder(destination)
          setStatus(`Moved to ${destination}.`)
        },
      })),
    },
    {
      label: 'Manage access',
      description: 'Only the owner can change permissions',
      icon: 'i-lucide:lock',
      disabled: true,
    },
    { type: 'separator' },
    {
      label: 'Move to trash',
      icon: 'i-lucide:trash-2',
      variant: 'danger',
      onSelect: () => {
        setDeleted(true)
        setStatus('Project brief.pdf moved to trash.')
      },
    },
  ])

  return (
    <section class="max-w-lg w-full space-y-3" aria-label="File actions example">
      <Show
        when={!deleted()}
        fallback={
          <div class="p-4 border border-border rounded-lg border-dashed flex gap-3 items-center justify-between">
            <span class="text-sm text-muted-foreground">File is in the trash</span>
            <Button
              variant="outline"
              onClick={() => {
                setDeleted(false)
                setStatus('Project brief.pdf restored.')
              }}
            >
              Undo
            </Button>
          </div>
        }
      >
        <ContextMenu>
          <ContextMenu.Trigger
            class="p-4 outline-none border border-border rounded-lg bg-card flex gap-3 select-none items-center focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-ring/50"
            aria-label="Actions for Project brief.pdf"
          >
            <Icon name="i-lucide:file-text" class="text-muted-foreground shrink-0 size-8" />
            <div class="flex-1 min-w-0">
              <p class="text-sm font-medium truncate">Project brief.pdf</p>
              <p class="text-xs text-muted-foreground">{folder()} · 240 KB</p>
            </div>
            <Show when={favorite()}>
              <Icon name="i-lucide:star" class="text-primary size-4" />
            </Show>
          </ContextMenu.Trigger>
          <ContextMenu.Content items={items()} />
        </ContextMenu>
      </Show>
      <p role="status" class="text-xs text-muted-foreground">
        {status()}
      </p>
    </section>
  )
}
```

### Pin an item and set priority

Checkbox and radio values live in application state. The status line reflects the current pin and
priority.

```tsx
import { ContextMenu } from 'moraine'
import type { ContextMenuT } from 'moraine'
import { createMemo, createSignal } from 'solid-js'

export function CheckboxRadio() {
  const [pinned, setPinned] = createSignal(false)
  const [priority, setPriority] = createSignal('normal')
  const items = createMemo<ContextMenuT.Item[]>(() => [
    { type: 'checkbox', label: 'Pin item', checked: pinned(), onCheckedChange: setPinned },
    { type: 'separator' },
    {
      type: 'radio-group',
      value: priority(),
      onValueChange: setPriority,
      items: [
        { type: 'radio', label: 'Low priority', value: 'low' },
        { type: 'radio', label: 'Normal priority', value: 'normal' },
        { type: 'radio', label: 'High priority', value: 'high' },
      ],
    },
  ])

  return (
    <div class="space-y-3">
      <ContextMenu>
        <ContextMenu.Trigger
          as="div"
          class="text-sm text-muted-foreground border border-border rounded-lg border-dashed flex h-28 max-w-sm select-none items-center justify-center"
        >
          Right click to change options
        </ContextMenu.Trigger>
        <ContextMenu.Content items={items()} />
      </ContextMenu>
      <p class="text-sm text-muted-foreground">
        Pinned: {String(pinned())}; priority: {priority()}
      </p>
    </div>
  )
}
```

### Sort from a nested menu

Nested children open a sort submenu. Refresh stays on the root menu.

```tsx
import { ContextMenu } from 'moraine'

export function Submenus() {
  return (
    <ContextMenu>
      <ContextMenu.Trigger
        as="div"
        class="text-sm text-muted-foreground border border-border rounded-lg border-dashed flex h-28 max-w-sm select-none items-center justify-center"
      >
        Right click for a submenu
      </ContextMenu.Trigger>
      <ContextMenu.Content
        items={[
          {
            label: 'Sort by',
            children: [
              {
                type: 'group',
                items: [
                  { label: 'Name', icon: 'i-lucide:arrow-down-a-z' },
                  { label: 'Modified date', icon: 'i-lucide:calendar-arrow-down' },
                ],
              },
            ],
          },
          { label: 'Refresh', icon: 'i-lucide:refresh-cw' },
        ]}
      />
    </ContextMenu>
  )
}
```

### Copy a note on long press

Touch and hold for about 700 ms, or right-click, to copy or delete the note.

```tsx
import { ContextMenu } from 'moraine'

export function LongPress() {
  return (
    <ContextMenu>
      <ContextMenu.Trigger
        as="div"
        class="text-sm text-muted-foreground text-center border border-border rounded-lg border-dashed flex h-32 max-w-sm select-none items-center justify-center touch-none"
      >
        Touch and hold for about 700 ms, or right click
      </ContextMenu.Trigger>
      <ContextMenu.Content
        items={[
          { label: 'Copy note', icon: 'i-lucide:copy' },
          { label: 'Delete note', variant: 'danger', icon: 'i-lucide:trash-2' },
        ]}
      />
    </ContextMenu>
  )
}
```

## API Reference

### Attributes

| Attributes | Slot | Description |
| --- | --- | --- |
| `data-closed` | `context-menu-trigger`, `context-menu-content` | Present when disclosure or transition content is closed. |
| `data-disabled` | `context-menu-trigger`, `context-menu-item` | Present when the component, slot, or item is disabled. |
| `data-expanded` | `context-menu-trigger`, `context-menu-content`, `context-menu-item` | Present when the panel, accordion, or menu is expanded. |
| `data-align` | `context-menu-content` | Stores the resolved alignment of positioned content. |
| `data-side` | `context-menu-content` | Stores the resolved floating or drawer content side. |
| `data-danger` | `context-menu-item` | Present when the action has danger semantics. |
| `data-highlighted` | `context-menu-item` | Present when the item is highlighted by pointer or keyboard navigation. |
| `data-selected` | `context-menu-item` | Present when the item or tab is selected. |

### Props

#### ContextMenu

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| align | 'start' \| 'center' \| 'end' \| undefined | 'start' | Alignment of the content along the cross axis relative to the anchor: `'start'`, `'center'` or `'end'`. |
| closeOnEscape | boolean \| undefined | true | Whether pressing Escape closes the menu. When `false`, Escape is ignored and `onClosePrevented`<br>is called. |
| closeOnOutsideClick | boolean \| undefined | true | Whether a pointer press or focus move outside the menu closes it. When `false`, the attempt<br>is ignored and `onClosePrevented` is called. |
| defaultOpen | boolean \| undefined | false | Initial open state when uncontrolled. Ignored when `open` is set. |
| disabled | boolean \| undefined | false | Disables the context menu: right-click, long press and keyboard opening no longer open it, the native browser menu shows instead, and an open menu closes. |
| flip | boolean \| string \| undefined | true | Whether the content moves to the opposite side when the preferred `placement` does not fit.<br>A space-delimited string such as `'top left'` is an ordered list of fallback placements<br>(`top`, `bottom`, `left` or `right`, each optionally followed by `-start` or `-end`); an<br>invalid entry throws. |
| gutter | number \| undefined | 4 | Distance in pixels between the anchor and the content along the placement axis. |
| id | string \| undefined | — | Base for the generated trigger and content ids; the content id is `<id>-content`. Generated<br>when omitted. |
| modal | boolean \| undefined | false | Whether the menu is modal: while it is open, content outside it is hidden from assistive<br>technology and the native default action of outside pointer presses is prevented. Outside<br>presses still dismiss the menu unless `closeOnOutsideClick` is `false`. |
| onClosePrevented | (() => void) \| undefined | — | Called when Escape or an outside interaction tries to close the menu but `closeOnEscape` or<br>`closeOnOutsideClick` is `false`. |
| onOpenChange | ((open: boolean) => void) \| undefined | — | Called with the next open state when the user opens or closes the menu, and when `disabled`<br>becomes `true` while it is open. It fires in controlled and uncontrolled mode alike, so a<br>controlled menu must write the value back to `open`. |
| open | boolean \| undefined | — | Controlled open state. While `undefined` the menu is uncontrolled and follows `defaultOpen`;<br>update it from `onOpenChange`. |
| overflowPadding | number \| undefined | 4 | Minimum distance in pixels kept between the content and the viewport edge when `flip` and<br>`slide` position it. |
| placement | 'top' \| 'right' \| 'bottom' \| 'left' \| undefined | 'right' | Preferred side of the pointer position (or the center of the trigger when opened from the keyboard) the content opens on (`'top'`, `'right'`, `'bottom'` or `'left'`).<br>The content may move to another side when `flip` is enabled and the preferred side lacks space. |
| preventScroll | boolean \| undefined | true | Locks body scroll while the menu is open and renders the `overlay` slot element behind the<br>content. Set `false` to keep the page scrollable. |
| shift | number \| undefined | 4 | Offset in pixels along the cross axis, applied on top of `align`. |
| size | 'sm' \| 'md' \| 'lg' \| undefined | 'md' | Visual size of menu items. |
| slide | boolean \| undefined | true | Whether the content may slide along the edge of the anchor so it stays inside the viewport<br>instead of being clipped. |
| children | JSX.Element \| undefined | — | Composed trigger and content primitives. |
| classes | Classes \| undefined | — | Family slot class defaults for this instance. |
| styles | Styles \| undefined | — | Family slot style defaults for this instance. |

#### ContextMenu.Trigger

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| disabled | boolean \| undefined | — | Whether this trigger is disabled. |
| as | T \| undefined | 'div' | Element or component to render as. |
| children | JSX.Element \| undefined | — | Trigger label and visual content. |
| class | SlotClassValue \| undefined | — | Class applied to the component root or trigger element. |
| style | SlotStyleValue \| undefined | — | Style applied to the component root or trigger element. |

#### ContextMenu.Content

Props for the ContextMenu content component.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| checkedIcon | IconT.Name \| undefined | 'icon-check' | Icon shown on checked checkbox and radio items. |
| expandIcon | IconT.Name \| undefined | 'icon-chevron-right' | Icon shown at the end of items that open a submenu. |
| footerRender | JSX.Element \| Component<FooterRenderProps> \| undefined | — | Content rendered below the item groups, in the root menu and in every submenu. A function is<br>mounted as a component and receives `{ sub }`, which is `true` inside a submenu. |
| headerRender | JSX.Element \| Component<HeaderRenderProps> \| undefined | — | Content rendered above the item groups, in the root menu and in every submenu. A function is<br>mounted as a component and receives `{ sub }`, which is `true` inside a submenu. |
| itemRender | Component<ItemRenderProps> \| undefined | — | Replaces the inner content of every item row (icon, label, description, shortcut keys, submenu<br>indicator and checkmark); the row keeps its role, keyboard handling and selection. It is<br>mounted as a component and receives `item`, `depth` (`0` in the root menu, `1` and up in<br>submenus) and `hasChildren`. Read `item.type` to tell checkbox and radio items apart. |
| items | ({<br>  /** Text or element shown as the item's primary text. A string `label` is also what typeahead<br>matches; otherwise the item's rendered text is used. When the menu content has an `itemRender`,<br>it replaces the default rendering of `label`, `description`, `icon` and `kbds`. */<br>  label?: JSX.Element;<br>  /** Secondary text shown below the label. */<br>  description?: JSX.Element;<br>  /** Name of the icon shown at the start of the item. */<br>  icon?: IconT.Name;<br>  /** Keys shown as keycaps at the end of the item, for example `['Ctrl', 'S']`. Display only: it<br>does not register a keyboard shortcut. Not shown on items that open a submenu. */<br>  kbds?: string[];<br>  /** Custom CSS class applied to the item element. */<br>  class?: ClassValue;<br>  /** Custom inline styles applied to the item element. */<br>  style?: JSX.CSSProperties;<br>  /** Visual treatment of the menu item. `'danger'` uses the danger text color for destructive<br>actions and sets `data-danger` on the item. */<br>  variant?: 'default' \| 'danger';<br>  /** Whether the item is non-interactive: it ignores activation (no `onSelect`, no closing) and<br>exposes `aria-disabled`. */<br>  disabled?: boolean;<br>  type?: 'item';<br>  /** Controlled open state of the submenu. Only applies to items with `children`; leave it<br>`undefined` to let the item manage its own state (see `defaultOpen`). */<br>  open?: boolean;<br>  /** Initial open state of the submenu when `open` is not set. */<br>  defaultOpen?: boolean;<br>  /** Called with the next open state when the submenu opens (pointer hover delay, click or arrow<br>key) or closes. Not called when `open` is changed from outside. */<br>  onOpenChange?: (open: boolean) => void;<br>  /** Items of the submenu, in the same shape as the menu `items` (flat items and `group` objects).<br>A non-empty list makes the item open a submenu instead of calling `onSelect`, and shows the<br>menu's `expandIcon` in place of `kbds`. */<br>  children?: OverlayMenuItem[];<br>  /** Called when the item is activated by click, Enter or Space, before the whole menu closes and<br>focus returns to the trigger. Not called for disabled items or items that open a submenu. */<br>  onSelect?: () => void;<br>} \| {<br>  /** Text or element shown as the item's primary text. A string `label` is also what typeahead<br>matches; otherwise the item's rendered text is used. When the menu content has an `itemRender`,<br>it replaces the default rendering of `label`, `description`, `icon` and `kbds`. */<br>  label?: JSX.Element;<br>  /** Secondary text shown below the label. */<br>  description?: JSX.Element;<br>  /** Name of the icon shown at the start of the item. */<br>  icon?: IconT.Name;<br>  /** Keys shown as keycaps at the end of the item, for example `['Ctrl', 'S']`. Display only: it<br>does not register a keyboard shortcut. Not shown on items that open a submenu. */<br>  kbds?: string[];<br>  /** Custom CSS class applied to the item element. */<br>  class?: ClassValue;<br>  /** Custom inline styles applied to the item element. */<br>  style?: JSX.CSSProperties;<br>  /** Visual treatment of the menu item. `'danger'` uses the danger text color for destructive<br>actions and sets `data-danger` on the item. */<br>  variant?: 'default' \| 'danger';<br>  /** Whether the item is non-interactive: it ignores activation (no `onSelect`, no closing) and<br>exposes `aria-disabled`. */<br>  disabled?: boolean;<br>  type: 'checkbox';<br>  /** Controlled checked state. Leave it `undefined` to let the item manage its own state (see<br>`defaultChecked`); when set, update it from `onCheckedChange`. */<br>  checked?: boolean;<br>  /** Initial checked state when `checked` is not set. */<br>  defaultChecked?: boolean;<br>  /** Called with the next checked state each time the user toggles the item. The menu stays open. */<br>  onCheckedChange?: (checked: boolean) => void;<br>  /** Called after `onCheckedChange` each time the item is toggled. The menu stays open. */<br>  onSelect?: () => void;<br>} \| {<br>  /** Text or element shown as the item's primary text. A string `label` is also what typeahead<br>matches; otherwise the item's rendered text is used. When the menu content has an `itemRender`,<br>it replaces the default rendering of `label`, `description`, `icon` and `kbds`. */<br>  label?: JSX.Element;<br>  /** Secondary text shown below the label. */<br>  description?: JSX.Element;<br>  /** Name of the icon shown at the start of the item. */<br>  icon?: IconT.Name;<br>  /** Keys shown as keycaps at the end of the item, for example `['Ctrl', 'S']`. Display only: it<br>does not register a keyboard shortcut. Not shown on items that open a submenu. */<br>  kbds?: string[];<br>  /** Custom CSS class applied to the item element. */<br>  class?: ClassValue;<br>  /** Custom inline styles applied to the item element. */<br>  style?: JSX.CSSProperties;<br>  /** Visual treatment of the menu item. `'danger'` uses the danger text color for destructive<br>actions and sets `data-danger` on the item. */<br>  variant?: 'default' \| 'danger';<br>  /** Whether the item is non-interactive: it ignores activation (no `onSelect`, no closing) and<br>exposes `aria-disabled`. */<br>  disabled?: boolean;<br>  type: 'radio-group';<br>  /** Radio items in this group. Selecting one unchecks the others. The group's `label`, when set,<br>is rendered as its heading. */<br>  items?: OverlayMenuRadioItem[];<br>  /** Controlled selected value, matched against each radio item's `value`. Leave it `undefined`<br>to let the group manage its own state (see `defaultValue`). */<br>  value?: string;<br>  /** Initial selected value when `value` is not set. */<br>  defaultValue?: string;<br>  /** Called with the `value` of the radio item the user chose. The menu stays open. */<br>  onValueChange?: (value: string) => void;<br>} \| {<br>  /** Text or element shown as the item's primary text. A string `label` is also what typeahead<br>matches; otherwise the item's rendered text is used. When the menu content has an `itemRender`,<br>it replaces the default rendering of `label`, `description`, `icon` and `kbds`. */<br>  label?: JSX.Element;<br>  /** Secondary text shown below the label. */<br>  description?: JSX.Element;<br>  /** Name of the icon shown at the start of the item. */<br>  icon?: IconT.Name;<br>  /** Keys shown as keycaps at the end of the item, for example `['Ctrl', 'S']`. Display only: it<br>does not register a keyboard shortcut. Not shown on items that open a submenu. */<br>  kbds?: string[];<br>  /** Custom CSS class applied to the item element. */<br>  class?: ClassValue;<br>  /** Custom inline styles applied to the item element. */<br>  style?: JSX.CSSProperties;<br>  /** Visual treatment of the menu item. `'danger'` uses the danger text color for destructive<br>actions and sets `data-danger` on the item. */<br>  variant?: 'default' \| 'danger';<br>  /** Whether the item is non-interactive: it ignores activation (no `onSelect`, no closing) and<br>exposes `aria-disabled`. */<br>  disabled?: boolean;<br>  type: 'group';<br>  /** Child items in this group. The group's `label`, when set, is rendered as a non-interactive<br>heading above the items. */<br>  items?: OverlayMenuItem[];<br>} \| {<br>  /** Text or element shown as the item's primary text. A string `label` is also what typeahead<br>matches; otherwise the item's rendered text is used. When the menu content has an `itemRender`,<br>it replaces the default rendering of `label`, `description`, `icon` and `kbds`. */<br>  label?: JSX.Element;<br>  /** Secondary text shown below the label. */<br>  description?: JSX.Element;<br>  /** Name of the icon shown at the start of the item. */<br>  icon?: IconT.Name;<br>  /** Keys shown as keycaps at the end of the item, for example `['Ctrl', 'S']`. Display only: it<br>does not register a keyboard shortcut. Not shown on items that open a submenu. */<br>  kbds?: string[];<br>  /** Custom CSS class applied to the item element. */<br>  class?: ClassValue;<br>  /** Custom inline styles applied to the item element. */<br>  style?: JSX.CSSProperties;<br>  /** Visual treatment of the menu item. `'danger'` uses the danger text color for destructive<br>actions and sets `data-danger` on the item. */<br>  variant?: 'default' \| 'danger';<br>  /** Whether the item is non-interactive: it ignores activation (no `onSelect`, no closing) and<br>exposes `aria-disabled`. */<br>  disabled?: boolean;<br>  type: 'separator';<br>} \| ({<br>  /** Text or element shown as the item's primary text. A string `label` is also what typeahead<br>matches; otherwise the item's rendered text is used. When the menu content has an `itemRender`,<br>it replaces the default rendering of `label`, `description`, `icon` and `kbds`. */<br>  label?: JSX.Element;<br>  /** Secondary text shown below the label. */<br>  description?: JSX.Element;<br>  /** Name of the icon shown at the start of the item. */<br>  icon?: IconT.Name;<br>  /** Keys shown as keycaps at the end of the item, for example `['Ctrl', 'S']`. Display only: it<br>does not register a keyboard shortcut. Not shown on items that open a submenu. */<br>  kbds?: string[];<br>  /** Custom CSS class applied to the item element. */<br>  class?: ClassValue;<br>  /** Custom inline styles applied to the item element. */<br>  style?: JSX.CSSProperties;<br>  /** Visual treatment of the menu item. `'danger'` uses the danger text color for destructive<br>actions and sets `data-danger` on the item. */<br>  variant?: 'default' \| 'danger';<br>  /** Whether the item is non-interactive: it ignores activation (no `onSelect`, no closing) and<br>exposes `aria-disabled`. */<br>  disabled?: boolean;<br>  type?: 'item';<br>  /** Controlled open state of the submenu. Only applies to items with `children`; leave it<br>`undefined` to let the item manage its own state (see `defaultOpen`). */<br>  open?: boolean;<br>  /** Initial open state of the submenu when `open` is not set. */<br>  defaultOpen?: boolean;<br>  /** Called with the next open state when the submenu opens (pointer hover delay, click or arrow<br>key) or closes. Not called when `open` is changed from outside. */<br>  onOpenChange?: (open: boolean) => void;<br>  /** Items of the submenu, in the same shape as the menu `items` (flat items and `group` objects).<br>A non-empty list makes the item open a submenu instead of calling `onSelect`, and shows the<br>menu's `expandIcon` in place of `kbds`. */<br>  children?: OverlayMenuItem[];<br>  /** Called when the item is activated by click, Enter or Space, before the whole menu closes and<br>focus returns to the trigger. Not called for disabled items or items that open a submenu. */<br>  onSelect?: () => void;<br>} \| {<br>  /** Text or element shown as the item's primary text. A string `label` is also what typeahead<br>matches; otherwise the item's rendered text is used. When the menu content has an `itemRender`,<br>it replaces the default rendering of `label`, `description`, `icon` and `kbds`. */<br>  label?: JSX.Element;<br>  /** Secondary text shown below the label. */<br>  description?: JSX.Element;<br>  /** Name of the icon shown at the start of the item. */<br>  icon?: IconT.Name;<br>  /** Keys shown as keycaps at the end of the item, for example `['Ctrl', 'S']`. Display only: it<br>does not register a keyboard shortcut. Not shown on items that open a submenu. */<br>  kbds?: string[];<br>  /** Custom CSS class applied to the item element. */<br>  class?: ClassValue;<br>  /** Custom inline styles applied to the item element. */<br>  style?: JSX.CSSProperties;<br>  /** Visual treatment of the menu item. `'danger'` uses the danger text color for destructive<br>actions and sets `data-danger` on the item. */<br>  variant?: 'default' \| 'danger';<br>  /** Whether the item is non-interactive: it ignores activation (no `onSelect`, no closing) and<br>exposes `aria-disabled`. */<br>  disabled?: boolean;<br>  type: 'checkbox';<br>  /** Controlled checked state. Leave it `undefined` to let the item manage its own state (see<br>`defaultChecked`); when set, update it from `onCheckedChange`. */<br>  checked?: boolean;<br>  /** Initial checked state when `checked` is not set. */<br>  defaultChecked?: boolean;<br>  /** Called with the next checked state each time the user toggles the item. The menu stays open. */<br>  onCheckedChange?: (checked: boolean) => void;<br>  /** Called after `onCheckedChange` each time the item is toggled. The menu stays open. */<br>  onSelect?: () => void;<br>} \| {<br>  /** Text or element shown as the item's primary text. A string `label` is also what typeahead<br>matches; otherwise the item's rendered text is used. When the menu content has an `itemRender`,<br>it replaces the default rendering of `label`, `description`, `icon` and `kbds`. */<br>  label?: JSX.Element;<br>  /** Secondary text shown below the label. */<br>  description?: JSX.Element;<br>  /** Name of the icon shown at the start of the item. */<br>  icon?: IconT.Name;<br>  /** Keys shown as keycaps at the end of the item, for example `['Ctrl', 'S']`. Display only: it<br>does not register a keyboard shortcut. Not shown on items that open a submenu. */<br>  kbds?: string[];<br>  /** Custom CSS class applied to the item element. */<br>  class?: ClassValue;<br>  /** Custom inline styles applied to the item element. */<br>  style?: JSX.CSSProperties;<br>  /** Visual treatment of the menu item. `'danger'` uses the danger text color for destructive<br>actions and sets `data-danger` on the item. */<br>  variant?: 'default' \| 'danger';<br>  /** Whether the item is non-interactive: it ignores activation (no `onSelect`, no closing) and<br>exposes `aria-disabled`. */<br>  disabled?: boolean;<br>  type: 'radio-group';<br>  /** Radio items in this group. Selecting one unchecks the others. The group's `label`, when set,<br>is rendered as its heading. */<br>  items?: OverlayMenuRadioItem[];<br>  /** Controlled selected value, matched against each radio item's `value`. Leave it `undefined`<br>to let the group manage its own state (see `defaultValue`). */<br>  value?: string;<br>  /** Initial selected value when `value` is not set. */<br>  defaultValue?: string;<br>  /** Called with the `value` of the radio item the user chose. The menu stays open. */<br>  onValueChange?: (value: string) => void;<br>} \| {<br>  /** Text or element shown as the item's primary text. A string `label` is also what typeahead<br>matches; otherwise the item's rendered text is used. When the menu content has an `itemRender`,<br>it replaces the default rendering of `label`, `description`, `icon` and `kbds`. */<br>  label?: JSX.Element;<br>  /** Secondary text shown below the label. */<br>  description?: JSX.Element;<br>  /** Name of the icon shown at the start of the item. */<br>  icon?: IconT.Name;<br>  /** Keys shown as keycaps at the end of the item, for example `['Ctrl', 'S']`. Display only: it<br>does not register a keyboard shortcut. Not shown on items that open a submenu. */<br>  kbds?: string[];<br>  /** Custom CSS class applied to the item element. */<br>  class?: ClassValue;<br>  /** Custom inline styles applied to the item element. */<br>  style?: JSX.CSSProperties;<br>  /** Visual treatment of the menu item. `'danger'` uses the danger text color for destructive<br>actions and sets `data-danger` on the item. */<br>  variant?: 'default' \| 'danger';<br>  /** Whether the item is non-interactive: it ignores activation (no `onSelect`, no closing) and<br>exposes `aria-disabled`. */<br>  disabled?: boolean;<br>  type: 'group';<br>  /** Child items in this group. The group's `label`, when set, is rendered as a non-interactive<br>heading above the items. */<br>  items?: OverlayMenuItem[];<br>} \| {<br>  /** Text or element shown as the item's primary text. A string `label` is also what typeahead<br>matches; otherwise the item's rendered text is used. When the menu content has an `itemRender`,<br>it replaces the default rendering of `label`, `description`, `icon` and `kbds`. */<br>  label?: JSX.Element;<br>  /** Secondary text shown below the label. */<br>  description?: JSX.Element;<br>  /** Name of the icon shown at the start of the item. */<br>  icon?: IconT.Name;<br>  /** Keys shown as keycaps at the end of the item, for example `['Ctrl', 'S']`. Display only: it<br>does not register a keyboard shortcut. Not shown on items that open a submenu. */<br>  kbds?: string[];<br>  /** Custom CSS class applied to the item element. */<br>  class?: ClassValue;<br>  /** Custom inline styles applied to the item element. */<br>  style?: JSX.CSSProperties;<br>  /** Visual treatment of the menu item. `'danger'` uses the danger text color for destructive<br>actions and sets `data-danger` on the item. */<br>  variant?: 'default' \| 'danger';<br>  /** Whether the item is non-interactive: it ignores activation (no `onSelect`, no closing) and<br>exposes `aria-disabled`. */<br>  disabled?: boolean;<br>  type: 'separator';<br>})[])[] \| undefined | — | Items rendered in the menu body. Each entry is an item object or an array of items; consecutive<br>plain entries form one group, and every array starts a new group, with a separator drawn<br>between groups. An item's `type` is `'item'` (the default), `'checkbox'`, `'radio-group'`<br>(with radio `items`), `'group'` (with a `label` and child `items`) or `'separator'`. An `'item'`<br>with `children` opens a submenu, and `onSelect` runs when an item is activated. |
| class | SlotClassValue \| undefined | — | Class applied to the component root or trigger element. |
| style | SlotStyleValue \| undefined | — | Style applied to the component root or trigger element. |

**`headerRender` example**

```tsx
import { ContextMenu } from 'moraine'

<ContextMenu>
  <ContextMenu.Trigger>Open</ContextMenu.Trigger>
  <ContextMenu.Content
    items={[{ label: 'Rename' }]}
    headerRender={(props) => <div>{props.sub ? 'More actions' : 'Actions'}</div>}
  />
</ContextMenu>
```

**`itemRender` example**

```tsx
import { ContextMenu } from 'moraine'

<ContextMenu>
  <ContextMenu.Trigger>Open</ContextMenu.Trigger>
  <ContextMenu.Content
    items={[{ label: 'Rename' }, { label: 'Share', children: [{ label: 'Copy link' }] }]}
    itemRender={(props) => (
      <span>
        {props.item.label}
        {props.hasChildren ? ' ›' : ''}
      </span>
    )}
  />
</ContextMenu>
```

**`items` example**

```tsx
import { createSignal } from 'solid-js'
import { ContextMenu } from 'moraine'

const [showHidden, setShowHidden] = createSignal(false)

<ContextMenu>
  <ContextMenu.Trigger>Open</ContextMenu.Trigger>
  <ContextMenu.Content
    items={[
      [{ label: 'Rename', onSelect: () => console.log('rename') }, { label: 'Delete', variant: 'danger' }],
      [{ type: 'checkbox', label: 'Show hidden', checked: showHidden(), onCheckedChange: setShowHidden }],
      { label: 'Share', children: [{ label: 'Copy link' }] },
    ]}
  />
</ContextMenu>
```
