Overview
ContextMenu is a custom right-click menu. Built without external libraries, it supports keyboard navigation and nested submenus.
- Compound — Root, Trigger, Content, Item, SubRoot, SubTrigger, SubContent
- Keyboard — Arrow keys, Home/End, Enter/Space, Escape
- Submenu — Nested submenus, openable via hover/keyboard
- Positioning — Displayed at click position, auto-adjusted within viewport
Basic Usage
Right-click here · Last action: Nothing yet
The Basic Usage example above includes a submenu (Sort By) and a disabled item (Paste).
Sub-components
| Prop | Type | Default | Required | Description |
|---|
children | ReactNode | - | Yes | Trigger and Content (Root) |
modal | boolean | false | No | Blocks interaction outside while open (Root) |
onOpenChange | (isOpen: boolean) => void | - | No | Called when the menu opens or closes (Root) |
| Prop | Type | Default | Required | Description |
|---|
children | ReactNode | - | Yes | Area that opens the menu on right-click or Shift+F10 |
isDisabled | boolean | - | No | Turns the menu off |
className | string | - | No | Extra CSS class |
style | CSSProperties | - | No | Inline style |
| Prop | Type | Default | Required | Description |
|---|
children | ReactNode | - | Yes | Items and submenus |
alignOffset | number | '0' | No | Vertical offset from the pointer in px |
isLoop | boolean | true | No | Arrow keys wrap from the last item to the first |
onEscapeKeyDown | (event: KeyboardEvent) => void | - | No | Called before Escape closes the menu |
className | string | - | No | Extra CSS class |
style | CSSProperties | - | No | Inline style |
| Prop | Type | Default | Required | Description |
|---|
children | ReactNode | - | Yes | Item text |
onSelect | () => void | - | No | Called when the item is chosen with a click, Enter or Space |
isDisabled | boolean | - | No | Disabled item. Skipped by the arrow keys |
textValue | string | - | No | Written to the data-value attribute of the item |
className | string | - | No | Extra CSS class |
style | CSSProperties | - | No | Inline style |
| Prop | Type | Default | Required | Description |
|---|
children | ReactNode | - | Yes | SubTrigger and SubContent |
isOpen | boolean | - | No | Open state (controlled) |
isDefaultOpen | boolean | - | No | First open state (uncontrolled) |
onOpenChange | (isOpen: boolean) => void | - | No | Called when the submenu opens or closes |
| Prop | Type | Default | Required | Description |
|---|
children | ReactNode | - | Yes | Item text. Opens the submenu on hover or Right arrow |
isDisabled | boolean | - | No | Disabled item |
textValue | string | - | No | Written to the data-value attribute of the item |
className | string | - | No | Extra CSS class |
style | CSSProperties | - | No | Inline style |
| Prop | Type | Default | Required | Description |
|---|
children | ReactNode | - | Yes | Submenu items |
isLoop | boolean | true | No | Arrow keys wrap |
sideOffset | number | '0' | No | Gap from the parent item in px |
alignOffset | number | '0' | No | Vertical offset in px |
onEscapeKeyDown | (event: KeyboardEvent) => void | - | No | Called before Escape closes the menu |
className | string | - | No | Extra CSS class |
style | CSSProperties | - | No | Inline style |
Specification
base
| 상태 | 요소 | 속성 | 값 |
|---|
| enabled | content | backgroundColor | $color.background.default.default |
| enabled | content | borderWidth | $size.stroke.border |
| enabled | content | borderColor | $color.border.default.default |
| enabled | content | borderRadius | $size.radius.200 |
| enabled | content | padding | $size.space.100 |
| enabled | item | paddingY | $size.space.200 |
| enabled | item | paddingX | $size.space.300 |
| enabled | item | gap | $size.space.200 |
| enabled | item | borderRadius | $size.radius.100 |
| enabled | item | color | $color.text.default.default |
| enabled | item | typography | $text.bodyBase |
| hover | item | backgroundColor | $color.background.default.defaultHover |
| focusVisible | item | outlineWidth | $size.stroke.focus |
| focusVisible | item | outlineStyle | solid토큰 아님 — no line style token |
| focusVisible | item | outlineColor | $color.border.focus.default |
| focusVisible | item | outlineOffset | -2px토큰 아님 — inside ring; no ring offset token |
| disabled | item | opacity | 0.5토큰 아님 — uses opacity, not the disabled color tokens (differs from Select) |
Keyboard Navigation
| Key | Action |
|---|
↑ / ↓ | Move between items |
Home / End | First/last item |
Enter / Space | Select item |
→ | Open submenu |
← | Close submenu |
Escape | Close menu |
Guidelines
- Right-click is ignored when an input/textarea has focus (browser default menu is used)
- The menu automatically closes on outside click or scroll
- Submenus open after 100ms hover and close after 150ms mouse leave