# ContextMenu

Pointer and keyboard context region with native shared menu content.

[All components](https://rickylabs.github.io/netscript/design-system/components/) · [Theme builder](https://rickylabs.github.io/netscript/create/) · [Implementation source](https://github.com/rickylabs/netscript/blob/main/packages/fresh-ui/registry/components/ui/context-menu.tsx)

## Live preview

[Open live context-menu preview](https://rickylabs.github.io/netscript/assets/fresh-ui/preview/?component=context-menu&theme=studio-utility)

## Install

```bash
netscript ui:add context-menu
```

## Usage and examples

The preview runs this JSX with the installed components. Import any composed primitives from your UI directory.

```tsx
import { useState } from 'preact/hooks';
import { Button } from '@app/components/ui/button.tsx';
import { ContextMenu } from '@app/components/ui/context-menu.tsx';

export function Example() {
  const [value, setValue] = useState('standard');
  const [open, setOpen] = useState(false);
  const [notice, report] = useState('');
  return (<><div><ContextMenu label="Order actions" items={[{id:"save",label:"Save order",onSelect:()=>report("Saved")}]}><Button variant="outline">Order actions</Button></ContextMenu></div><p role="status">{notice}</p></>);
}
```

## Props

Generated from native `deno doc --json --private` over the shipped implementation. Compound component props retain their owning interface; native attributes pass through where declared.

| Owner | Prop | Type | Optional | Description |
| --- | --- | --- | --- | --- |
| `ContextMenuProps` | `label` | `string` | No |  |
| `ContextMenuProps` | `items` | `[object Object]` | No |  |
| `ContextMenuProps` | `children` | `ComponentChildren` | No |  |
| `ContextMenuProps` | `open` | `boolean` | Yes |  |
| `ContextMenuProps` | `defaultOpen` | `boolean` | Yes |  |
| `ContextMenuProps` | `onOpenChange` | `(open: boolean) => void` | Yes |  |
| `ContextMenuProps` | `disabled` | `boolean` | Yes |  |
| `ContextMenuProps` | `class` | `string` | Yes |  |

```typescript
ContextMenuProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, "class">
```

## Keyboard

| Key | Action |
| --- | --- |
| `ArrowUp/ArrowDown` | Navigate items |
| `Enter/Space` | Activate focused item |
| `Escape` | Dismiss menu |
| `Shift+F10/ContextMenu` | Open at the focused context region. |
| `Home/End/printable character` | Traverse current menu using shared ActionMenu behavior. |
| `Tab/Shift+Tab` | Close and leave through the native focusable region. |

## Tokens

Semantic contract roles: `surface/card`, `text/fg`.

CSS custom properties referenced directly: `--ns-border`, `--ns-border-width`, `--ns-floating-fallback-inset`, `--ns-muted-fg`, `--ns-ring`, `--ns-space-16`, `--ns-space-4`, `--ns-text-small`.

## Contract and compatibility

Accessibility pattern: [WAI-ARIA guidance](https://www.w3.org/WAI/ARIA/apg/patterns/menu/)

- Focusable native group region supports pointer contextmenu and Shift+F10/ContextMenu invocation; rich content can retain its own native semantics.
- Shared ActionMenu content owns menu keys and choices/submenus; native top layer plus fixed client coordinates provide pointer placement and viewport clamping.
- Explicit Escape/action restores context-region focus; outside dismissal keeps its destination. Browser-forced native dismissal remains platform-owned.

Design contract values marked planned are not implementation props. The props above describe what ships today.
