# ContextMenu

> A right-click menu attached to a region.

- Category: [Overlays](https://tarve.dev/docs.md#overlays)
- Import: `import { ContextMenu } from "@tarve/core";`
- Props type: `ContextMenuProps`
- Source: [packages/core/src/popups.ts:421](https://github.com/omarcosr/tarve/blob/main/packages/core/src/popups.ts#L421)

## Usage

```tsx title="ContextMenu.tsx"
import { ContextMenu, Text, View } from "@tarve/core";

let open = true;

<ContextMenu
  id="canvas-menu"
  open={open}
  trigger={
    <View padding={40}>
      <Text>Right-click here</Text>
    </View>
  }
  items={[
    { value: "copy", label: "Copy", shortcut: "Ctrl+C" },
    { value: "paste", label: "Paste", shortcut: "Ctrl+V" },
  ]}
  onOpenChange={(next) => {
    open = next;
  }}
  onSelect={(value) => console.log(value)}
/>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `id` (required) | `string` | — |  |
| `items` (required) | `readonly DropdownMenuItem[]` | — |  |
| `open` (required) | `boolean` | — |  |
| `trigger` (required) | `Child` | — |  |
| `contentStyle` | `Style` | — |  |
| `disabled` | `boolean` | `false` |  |
| `label` | `string` | — |  |
| `onOpenChange` | `(open: boolean) => void` | — |  |
| `onSelect` | `(value: string) => void` | — |  |
| `side` | `PopupSide` | `"bottom"` |  |

## Common props

Shared by every component (descriptions: https://tarve.dev/docs.md#common-props): `children`, `class`, `className`, `highlight`, `key`, `motionFrom`, `onHighlight`, `onPaste`, `onPointerLeave`, `onPointerMove`, `onSize`, `onTransitionEnd`, `rovingGroup`, `style`.

## Types

```ts title="DropdownMenuItem"
interface DropdownMenuItem {
  value: string;
  label: string;
  icon?: IconName;
  shortcut?: string;
  disabled?: boolean;
  checked?: boolean;
}
```

```ts title="PopupSide"
type PopupSide = "top" | "right" | "bottom" | "left";
```

Previous: [DropdownMenu](https://tarve.dev/docs/components/DropdownMenu.md) · Next: [Command](https://tarve.dev/docs/components/Command.md)

---

Tarve v0.13.8 · HTML version: https://tarve.dev/docs/components/ContextMenu · Index for agents: https://tarve.dev/llms.txt
