ContextMenu
Pointer and keyboard context region with native shared menu content.
All components · Theme builder · Implementation source
Live preview
Open live context-menu preview
Install
netscript ui:add context-menuUsage and examples
The preview runs this JSX with the installed components. Import any composed primitives from your UI directory.
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 |
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
- 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.