Overlay
Context Menu
Right-click menu with items, checkboxes, radio groups, submenus, and shortcuts.
Install
pnpm add @codefast/ui
Import path
@codefast/ui/context-menu
Examples
Anatomy
How the parts compose. Copy this skeleton and fill in the slots.
import {
ContextMenu, ContextMenuTrigger, ContextMenuContent,
ContextMenuItem, ContextMenuCheckboxItem, ContextMenuRadioGroup,
} from "@codefast/ui/context-menu";
<ContextMenu>
<ContextMenuTrigger>…</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem>…</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
API reference
Props for each part of the component. All native element props are also forwarded.
ContextMenuTrigger
The region that opens the menu on right-click (or long-press).
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | The area users right-click. Style it however you like. |
ContextMenuCheckboxItem / RadioGroup
| Prop | Type | Default | Description |
|---|---|---|---|
| checked / onCheckedChange | boolean / (checked: boolean) => void | — | On a checkbox item: its toggled state. |
| value / onValueChange | string / (value: string) => void | — | On a radio group: the selected RadioItem value. |
ContextMenuSub
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | — | Pair ContextMenuSubTrigger with ContextMenuSubContent for a submenu. |
Accessibility
Built to be keyboard-navigable and screen-reader friendly out of the box.
| Key | Function |
|---|---|
| Arrow+Down | Moves to the next item (once open). |
| Arrow+Right | Opens the focused submenu. |
| Enter | Activates the focused item. |
| Esc | Closes the menu. |
- Opens with the context-menu key or long-press, not just right-click.
- Checkbox and radio items expose aria-checked for assistive tech.
- Always offer the same actions elsewhere — a context menu must not be the only path.
Guidelines
Conventions that keep usage consistent across an app.
Do
- Use for contextual shortcuts on an element (canvas, row, file).
- Mirror the most-used items in a visible toolbar or button menu.
Don’t
- Don’t hide primary actions only behind right-click.
- Don’t nest submenus more than one level deep.