Context Menu
Displays a menu of actions triggered by a right click.
Installation
pnpm dlx cubix@latest add context-menuUsage
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuTrigger,
} from "@/components/cubix/context-menu"<ContextMenu>
<ContextMenuTrigger>Right click here</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem>Profile</ContextMenuItem>
<ContextMenuItem>Billing</ContextMenuItem>
<ContextMenuItem>Team</ContextMenuItem>
<ContextMenuItem>Subscription</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>Composition
Use the following composition to build a ContextMenu:
ContextMenu
├── ContextMenuTrigger
└── ContextMenuContent
├── ContextMenuGroup
│ ├── ContextMenuLabel
│ ├── ContextMenuItem
│ └── ContextMenuItem
├── ContextMenuSeparator
├── ContextMenuGroup
│ ├── ContextMenuLabel
│ ├── ContextMenuCheckboxItem
│ └── ContextMenuCheckboxItem
├── ContextMenuSeparator
├── ContextMenuGroup
│ ├── ContextMenuLabel
│ └── ContextMenuRadioGroup
│ ├── ContextMenuRadioItem
│ └── ContextMenuRadioItem
└── ContextMenuSub
├── ContextMenuSubTrigger
└── ContextMenuSubContent
└── ContextMenuGroup
├── ContextMenuItem
└── ContextMenuItemExamples
Basic
A simple context menu with a few actions.
Submenu
Use ContextMenuSub to nest secondary actions.
Shortcuts
Add ContextMenuShortcut to show keyboard hints.
Groups
Group related actions and separate them with dividers.
Icons
Combine icons with labels for quick scanning.
Checkboxes
Use ContextMenuCheckboxItem for toggles.
Radio
Use ContextMenuRadioItem for exclusive choices.
Destructive
Use variant="destructive" to style the menu item as destructive.
Sides
Control submenu placement with side and align props.
API Reference
Note: See the Base UI documentation for more information.
ContextMenu
The container that wraps the trigger and content and manages open state.
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | - | Controlled open state. Omit to use uncontrolled mode. |
| defaultOpen | boolean | false | Initial open state when uncontrolled. |
| onOpenChange | (open: boolean) => void | - | Called when the open state changes. |
| children | React.ReactNode | - | The trigger, content, and nested menu parts. |
ContextMenuTrigger
The area that opens the menu on right click or long press.
| Prop | Type | Default | Description |
|---|---|---|---|
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
| children | React.ReactNode | - | The surface that opens the menu on right click or long press. |
ContextMenuContent
The menu panel rendered in a portal next to the pointer.
| Prop | Type | Default | Description |
|---|---|---|---|
| side | "top" | "right" | "bottom" | "left" | "right" | Preferred side of the pointer to render the menu on. |
| align | "start" | "center" | "end" | "start" | Alignment along the opposite axis of `side`. |
| sideOffset | number | 0 | Distance in pixels between the pointer and the menu. |
| alignOffset | number | 4 | Offset in pixels along the alignment axis. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
ContextMenuItem
An action inside the menu. Selecting it closes the menu.
| Prop | Type | Default | Description |
|---|---|---|---|
| inset | boolean | - | Indent the item to align with items that have a leading icon. |
| variant | "default" | "destructive" | "default" | Visual treatment. Use destructive for irreversible actions. |
| disabled | boolean | - | Prevents selection and removes the item from keyboard flow. |
| onSelect | (event: Event) => void | - | Called when the item is chosen. The menu closes afterwards. |
ContextMenuCheckboxItem
A checkable item. The menu stays open after toggling.
| Prop | Type | Default | Description |
|---|---|---|---|
| checked | boolean | - | Controlled checked state. |
| defaultChecked | boolean | - | Initial checked state when uncontrolled. |
| onCheckedChange | (checked: boolean) => void | - | Called when the checked state changes. The menu stays open. |
| disabled | boolean | - | Prevents toggling the item. |
ContextMenuRadioGroup
A set of mutually exclusive items. The menu stays open after a change.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | Controlled selected value. |
| defaultValue | string | - | Initial selected value when uncontrolled. |
| onValueChange | (value: string) => void | - | Called when a radio item is selected. The menu stays open. |
ContextMenuRadioItem
One option inside a radio group. value is required.
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | The unique value represented by this radio item. |
| disabled | boolean | - | Prevents selecting the item. |