ContextMenu
Menu triggered by right-click or long press on its child content.
Import#
Slot Structure#
Right-click trigger with a floating menu portal containing grouped items.
Use contentProps and itemProps to forward native attributes, refs, and event handlers. Item handlers run before built-in menu behavior and can call preventDefault() to cancel activation.
Menu#
Item internals#
Examples#
Sizes#
Menu item size scale from sm to lg for compact and roomy density.
Placements#
Same file menu rendered with top/right/bottom/left placements for quick transition-direction sanity checks.
File Explorer#
A file-row context menu with move flows, shortcuts, mixed labels, and destructive actions.
Editor Selection#
A code-editor-style context menu with refactors, toggles, and theme switching for keyboard and pointer testing.
Project / Issue Actions#
A denser project card menu with assignee and sprint submenus plus archive/delete actions.
API Reference#
Attributes#
trigger6 attributesData Attributes
| Data Attribute | Description |
|---|---|
| data-closed | State or slot attribute exposed for styling hooks and selectors. |
| data-disabled | Present when the component or item is disabled. |
| data-expanded | State or slot attribute exposed for styling hooks and selectors. |
ARIA Attributes
| ARIA Attribute | Description |
|---|---|
| aria-controls | References the controlled element while the related content is mounted. |
| aria-expanded | Indicates whether the controlled content is expanded. |
| aria-haspopup | Accessibility attribute forwarded by the rendered component. |
Props#
| Prop | Type | Default | Description |
|---|---|---|---|
| checkedIcon | IconT.Name | icon-check | Icon used for checked checkbox items. |
| children | JSX.Element | — | Target area that opens the context menu on right-click or long press. |
| class | ClassValue | — | Class applied to the component root or trigger element. |
| classes | (OverlayMenuSharedClasses & ContextMenuT.Classes) | undefined | — | Slot class overrides for menu sections. |
| contentBottom | OverlayMenuContentSlot | undefined | — | Content rendered after the resolved item groups. |
| contentProps | ElementProps<HTMLDivElement> | undefined | — | Additional attributes for each menu layer content element. |
| contentTop | OverlayMenuContentSlot | undefined | — | Content rendered before the resolved item groups. |
| defaultOpen | boolean | undefined | false | Initial open state when the component is uncontrolled. |
| disabled | boolean | undefined | false | Whether trigger interactions should be ignored. |
| gutter | number | undefined | 0 | Gap between the anchor and the content. |
| id | string | undefined | — | Unique base id used to derive trigger and content ids. |
| itemProps | ((props: ContextMenuT.ItemRenderProps) => ElementProps<HTMLDivElement> | undefined) | undefined | — | Additional attributes for an interactive menu item. |
| itemRender | ComponentOrElement<ContextMenuT.ItemRenderProps> | undefined | — | Custom renderer for individual items. |
| items | ContextMenuT.Item[] | undefined | — | Items rendered in the menu body. |
| onContextMenu | JSX.EventHandlerUnion<HTMLSpanElement, MouseEvent> | undefined | — | — |
| onKeyDown | JSX.EventHandlerUnion<HTMLSpanElement, KeyboardEvent> | undefined | — | — |
| onOpenChange | ((open: boolean) => void) | undefined | — | Called whenever the menu requests an open state change. |
| onPointerCancel | JSX.EventHandlerUnion<HTMLSpanElement, PointerEvent> | undefined | — | — |
| onPointerDown | JSX.EventHandlerUnion<HTMLSpanElement, PointerEvent> | undefined | — | — |
| onPointerMove | JSX.EventHandlerUnion<HTMLSpanElement, PointerEvent> | undefined | — | — |
| onPointerUp | JSX.EventHandlerUnion<HTMLSpanElement, PointerEvent> | undefined | — | — |
| open | boolean | undefined | — | Controlled open state of the menu. |
| overflowPadding | number | undefined | 4 | Padding applied to the overflow area when calculating the menu's position. |
| placement | OverlayMenuPlacement | undefined | — | Preferred content placement relative to the trigger or anchor point. |
| preventScroll | boolean | undefined | true | Whether body scroll should be locked while the menu is open. |
| ref | JSX.HTMLElementTags["span"] extends { ref?: infer Ref; } ? Ref : never | undefined | — | — |
| size | "sm" | "md" | "lg" | undefined | md | Menu item size variant. |
| style | JSX.CSSProperties | undefined | — | — |
| styles | (OverlayMenuSharedStyles & ContextMenuT.Styles) | undefined | — | Slot style overrides for menu sections. |
| submenuIcon | IconT.Name | icon-chevron-right | Icon used for submenu trigger items. |
Items#
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | boolean | undefined | — | Controlled checked state for checkbox and radio items. |
| children | ContextMenuT.Item[] | undefined | — | Nested menu items for creating submenus. |
| color | NonNullable<"default" | "destructive" | undefined> | undefined | — | Color theme variant for the menu item. |
| defaultChecked | boolean | undefined | — | Initial checked state for uncontrolled checkbox and radio items. |
| defaultOpen | boolean | undefined | — | Initial open state for submenus. |
| description | JSX.Element | — | Secondary description text displayed below the label. |
| disabled | boolean | undefined | false | Whether the item is non-interactive. |
| group | string | undefined | — | Radio group identifier. Radio items with the same group are mutually exclusive. |
| icon | IconT.Name | — | Icon name or custom element to display at the start of the item. |
| kbds | string[] | undefined | — | Array of keyboard shortcuts to display as keys. |
| label | JSX.Element | — | Primary label text or element. |
| onCheckedChange | ((checked: boolean) => void) | undefined | — | Event handler called when a checkbox item's state changes. |
| onSelect | (() => void) | undefined | — | Event handler called when the item is activated. |
| onValueChange | ((value: string) => void) | undefined | — | Event handler called when a radio item is selected. |
| open | boolean | undefined | — | Controlled open state for submenus. |
| type | OverlayMenuItemType | undefined | item | The type of menu item to render. |
| value | string | undefined | — | Radio item value reported by onValueChange and used for grouped selection. |