Components

ContextMenu

Custom right-click context menu with nested submenu support

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

ContextMenu.Root

PropTypeDefaultRequiredDescription
childrenReactNode-YesTrigger and Content (Root)
modalbooleanfalseNoBlocks interaction outside while open (Root)
onOpenChange(isOpen: boolean) => void-NoCalled when the menu opens or closes (Root)

ContextMenu.Trigger

PropTypeDefaultRequiredDescription
childrenReactNode-YesArea that opens the menu on right-click or Shift+F10
isDisabledboolean-NoTurns the menu off
classNamestring-NoExtra CSS class
styleCSSProperties-NoInline style

ContextMenu.Content

PropTypeDefaultRequiredDescription
childrenReactNode-YesItems and submenus
alignOffsetnumber'0'NoVertical offset from the pointer in px
isLoopbooleantrueNoArrow keys wrap from the last item to the first
onEscapeKeyDown(event: KeyboardEvent) => void-NoCalled before Escape closes the menu
classNamestring-NoExtra CSS class
styleCSSProperties-NoInline style

ContextMenu.Item

PropTypeDefaultRequiredDescription
childrenReactNode-YesItem text
onSelect() => void-NoCalled when the item is chosen with a click, Enter or Space
isDisabledboolean-NoDisabled item. Skipped by the arrow keys
textValuestring-NoWritten to the data-value attribute of the item
classNamestring-NoExtra CSS class
styleCSSProperties-NoInline style

ContextMenu.SubRoot

PropTypeDefaultRequiredDescription
childrenReactNode-YesSubTrigger and SubContent
isOpenboolean-NoOpen state (controlled)
isDefaultOpenboolean-NoFirst open state (uncontrolled)
onOpenChange(isOpen: boolean) => void-NoCalled when the submenu opens or closes

ContextMenu.SubTrigger

PropTypeDefaultRequiredDescription
childrenReactNode-YesItem text. Opens the submenu on hover or Right arrow
isDisabledboolean-NoDisabled item
textValuestring-NoWritten to the data-value attribute of the item
classNamestring-NoExtra CSS class
styleCSSProperties-NoInline style

ContextMenu.SubContent

PropTypeDefaultRequiredDescription
childrenReactNode-YesSubmenu items
isLoopbooleantrueNoArrow keys wrap
sideOffsetnumber'0'NoGap from the parent item in px
alignOffsetnumber'0'NoVertical offset in px
onEscapeKeyDown(event: KeyboardEvent) => void-NoCalled before Escape closes the menu
classNamestring-NoExtra CSS class
styleCSSProperties-NoInline style

Specification

base

상태요소속성값
enabledcontentbackgroundColor$color.background.default.default
enabledcontentborderWidth$size.stroke.border
enabledcontentborderColor$color.border.default.default
enabledcontentborderRadius$size.radius.200
enabledcontentpadding$size.space.100
enableditempaddingY$size.space.200
enableditempaddingX$size.space.300
enableditemgap$size.space.200
enableditemborderRadius$size.radius.100
enableditemcolor$color.text.default.default
enableditemtypography$text.bodyBase
hoveritembackgroundColor$color.background.default.defaultHover
focusVisibleitemoutlineWidth$size.stroke.focus
focusVisibleitemoutlineStylesolid토큰 아님 — no line style token
focusVisibleitemoutlineColor$color.border.focus.default
focusVisibleitemoutlineOffset-2px토큰 아님 — inside ring; no ring offset token
disableditemopacity0.5토큰 아님 — uses opacity, not the disabled color tokens (differs from Select)

Keyboard Navigation

KeyAction
↑ / ↓Move between items
Home / EndFirst/last item
Enter / SpaceSelect item
→Open submenu
←Close submenu
EscapeClose 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