# Context Menu

Displays a menu of actions triggered by a right click.

Section: Components / Overlays
Page: https://ui.heyramzi.com/components/context-menu
Import path: `@heyramzi/ui/shadcn/context-menu`

## Import

```ts
import * as ContextMenu from "@heyramzi/ui/shadcn/context-menu";
```

## Usage

```svelte
<ContextMenu.Root>
  <ContextMenu.Trigger>Right click here</ContextMenu.Trigger>
  <ContextMenu.Content>
    <ContextMenu.Item>
      Back
      <ContextMenu.Shortcut>⌘[</ContextMenu.Shortcut>
    </ContextMenu.Item>
    <ContextMenu.Item>Reload</ContextMenu.Item>
    <ContextMenu.Separator />
    <ContextMenu.CheckboxItem bind:checked={showBookmarks}>Show bookmarks</ContextMenu.CheckboxItem>
  </ContextMenu.Content>
</ContextMenu.Root>
```

## Demo

```svelte
<script lang="ts">
	import * as ContextMenu from "@heyramzi/ui/shadcn/context-menu";

	let showBookmarks = $state(false);
	let showFullURLs = $state(true);

	let value = $state("pedro");
</script>

<ContextMenu.Root>
	<ContextMenu.Trigger
		class="flex h-[150px] w-[300px] items-center justify-center rounded-md border border-dashed text-sm"
	>
		Right click here
	</ContextMenu.Trigger>
	<ContextMenu.Content class="w-52">
		<ContextMenu.Item>
			Back
			<ContextMenu.Shortcut>⌘[</ContextMenu.Shortcut>
		</ContextMenu.Item>
		<ContextMenu.Item disabled>
			Forward
			<ContextMenu.Shortcut>⌘]</ContextMenu.Shortcut>
		</ContextMenu.Item>
		<ContextMenu.Item>
			Reload
			<ContextMenu.Shortcut>⌘R</ContextMenu.Shortcut>
		</ContextMenu.Item>
		<ContextMenu.Sub>
			<ContextMenu.SubTrigger>More Tools</ContextMenu.SubTrigger>
			<ContextMenu.SubContent class="w-48">
				<ContextMenu.Item>
					Save Page As...
					<ContextMenu.Shortcut>⇧⌘S</ContextMenu.Shortcut>
				</ContextMenu.Item>
				<ContextMenu.Item>Create Shortcut...</ContextMenu.Item>
				<ContextMenu.Item>Name Window...</ContextMenu.Item>
				<ContextMenu.Separator />
				<ContextMenu.Item>Developer Tools</ContextMenu.Item>
			</ContextMenu.SubContent>
		</ContextMenu.Sub>
		<ContextMenu.Separator />
		<ContextMenu.CheckboxItem bind:checked={showBookmarks}>Show Bookmarks</ContextMenu.CheckboxItem>
		<ContextMenu.CheckboxItem bind:checked={showFullURLs}>Show Full URLs</ContextMenu.CheckboxItem>
		<ContextMenu.Separator />
		<ContextMenu.RadioGroup bind:value>
			<ContextMenu.Group>
				<ContextMenu.Label>People</ContextMenu.Label>
				<ContextMenu.RadioItem value="pedro">Pedro Duarte</ContextMenu.RadioItem>
				<ContextMenu.RadioItem value="colm">Colm Tuite</ContextMenu.RadioItem>
			</ContextMenu.Group>
		</ContextMenu.RadioGroup>
	</ContextMenu.Content>
</ContextMenu.Root>
```

## API

### ContextMenu.Root

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `open` | `boolean` | `false` | bindable |

Every prop of `ContextMenu.Root` from `bits-ui`.

### ContextMenu.Trigger

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |

Every prop of `ContextMenu.Trigger` from `bits-ui`.

### ContextMenu.Content

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `portalProps` | `WithoutChildrenOrChild<ComponentProps<typeof ContextMenuPortal>>` |  |  |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |

Every prop of `ContextMenu.Content` from `bits-ui`.

### ContextMenu.Item

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `inset` | `boolean` |  |  |
| `variant` | `"default" \| "destructive"` | `"default"` |  |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |

Every prop of `ContextMenu.Item` from `bits-ui`.

### ContextMenu.Shortcut

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLSpanElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLSpanElement>` from `svelte/elements`.

### ContextMenu.Sub

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `open` | `boolean` | `false` | bindable |

Every prop of `ContextMenu.Sub` from `bits-ui`.

### ContextMenu.SubTrigger

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `inset` | `boolean` |  |  |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `ContextMenu.SubTrigger` from `bits-ui`, except `child`.

### ContextMenu.SubContent

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |

Every prop of `ContextMenu.SubContent` from `bits-ui`.

### ContextMenu.Separator

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |

Every prop of `ContextMenu.Separator` from `bits-ui`.

### ContextMenu.CheckboxItem

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `inset` | `boolean` |  |  |
| `children` | `Snippet` |  |  |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `checked` | `boolean` | `false` | bindable |
| `indeterminate` | `boolean` | `false` | bindable |
| `class` | `string` |  |  |

Every prop of `ContextMenu.CheckboxItem` from `bits-ui`, except `child, children`.

### ContextMenu.RadioGroup

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `value` | `string` | `""` | bindable |

Every prop of `ContextMenu.RadioGroup` from `bits-ui`.

### ContextMenu.Group

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `ref` | `HTMLElement \| null` | `null` | bindable |

Every prop of `ContextMenu.Group` from `bits-ui`.

### ContextMenu.Label

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `inset` | `boolean` |  |  |
| `ref` | `HTMLDivElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `HTMLAttributes<HTMLDivElement>` from `svelte/elements`.

### ContextMenu.RadioItem

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `inset` | `boolean` |  |  |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |
| `children` | `Snippet` |  |  |

Every prop of `ContextMenu.RadioItem` from `bits-ui`, except `child`.

### ContextMenu.Portal

Every prop of `ContextMenu.Portal` from `bits-ui`.

### ContextMenu.GroupHeading

| Prop | Type | Default | Notes |
| --- | --- | --- | --- |
| `inset` | `boolean` |  |  |
| `ref` | `HTMLElement \| null` | `null` | bindable |
| `class` | `string` |  |  |

Every prop of `ContextMenu.GroupHeading` from `bits-ui`.
