Context Menu

Displays a menu of actions triggered by a right click.

Right click here

Installation

pnpm dlx cubix@latest add context-menu --base radix

Usage

Import
import {
  ContextMenu,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuTrigger,
} from "@/components/cubix/context-menu"
Example
<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
                └── ContextMenuItem

Examples

Basic

A simple context menu with a few actions.

Right click here

Submenu

Use ContextMenuSub to nest secondary actions.

Right click here

Shortcuts

Add ContextMenuShortcut to show keyboard hints.

Right click here

Groups

Group related actions and separate them with dividers.

Right click here

Icons

Combine icons with labels for quick scanning.

Right click here

Checkboxes

Use ContextMenuCheckboxItem for toggles.

Right click here

Radio

Use ContextMenuRadioItem for exclusive choices.

Right click here

Destructive

Use variant="destructive" to style the menu item as destructive.

Right click here

Sides

Control submenu placement with side and align props.

Right click (top)
Right click (right)
Right click (bottom)
Right click (left)

API Reference

Note: See the Base UI documentation for more information.

ContextMenu

The container that wraps the trigger and content and manages open state.

PropTypeDefaultDescription
openboolean-Controlled open state. Omit to use uncontrolled mode.
defaultOpenbooleanfalseInitial open state when uncontrolled.
onOpenChange(open: boolean) => void-Called when the open state changes.
childrenReact.ReactNode-The trigger, content, and nested menu parts.

ContextMenuTrigger

The area that opens the menu on right click or long press.

PropTypeDefaultDescription
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).
childrenReact.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.

PropTypeDefaultDescription
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`.
sideOffsetnumber0Distance in pixels between the pointer and the menu.
alignOffsetnumber4Offset in pixels along the alignment axis.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

ContextMenuItem

An action inside the menu. Selecting it closes the menu.

PropTypeDefaultDescription
insetboolean-Indent the item to align with items that have a leading icon.
variant"default" | "destructive""default"Visual treatment. Use destructive for irreversible actions.
disabledboolean-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.

PropTypeDefaultDescription
checkedboolean-Controlled checked state.
defaultCheckedboolean-Initial checked state when uncontrolled.
onCheckedChange(checked: boolean) => void-Called when the checked state changes. The menu stays open.
disabledboolean-Prevents toggling the item.

ContextMenuRadioGroup

A set of mutually exclusive items. The menu stays open after a change.

PropTypeDefaultDescription
valuestring-Controlled selected value.
defaultValuestring-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.

PropTypeDefaultDescription
valuestring-The unique value represented by this radio item.
disabledboolean-Prevents selecting the item.