Skip to content

Now in the official shadcn registry directory.

Start free

Context Menu

A right-click menu with danger items, checkbox items, radio groups, submenus and shortcuts.

overlay
A free styled version is available
Right click here

Installation

Run the following command

npx shadcn@latest add @ai2/context-menu

Dependencies, the @ai2/tokens theme and the component file are installed together.

Usage

TS
import {
  ContextMenu,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuSeparator,
  ContextMenuTrigger,
} from "@/components/ui/context-menu"

<ContextMenu>
  <ContextMenuTrigger className="flex h-32 w-full items-center justify-center rounded-xl border border-dashed">
    Right click here
  </ContextMenuTrigger>
  <ContextMenuContent>
    <ContextMenuItem>Copy</ContextMenuItem>
    <ContextMenuSeparator />
    <ContextMenuItem variant="danger">Delete</ContextMenuItem>
  </ContextMenuContent>
</ContextMenu>

The ContextMenuTrigger is the right-click surface itself, so give it a size. The menu opens at the pointer, portals to the body and is fully keyboard navigable once open.

Examples

Item variants and states

Right click here

Both item variants in one menu: default for plain actions and variant="danger" for destructive ones, plus the inset and disabled states and a right-aligned ContextMenuShortcut.

Checkbox and radio items

Right click here

Checkbox items toggle independently with checked and onCheckedChange; the radio group gives an exclusive choice via value and onValueChange.

Right click here

Props

All parts forward their radix ContextMenu props: onSelect and disabled on items, onOpenChange on the root. The ai2-specific props:

ContextMenuItem props

PropTypeDefaultDescription
variant"default" | "danger""default"danger colors the item (and its icons) with the danger tone for destructive actions.
insetboolean-Adds left padding so plain items align with checkbox and radio items. Also available on ContextMenuLabel and ContextMenuSubTrigger.

ai2 Context Menu: a right-click action menu for React

The ai2 Context Menu is a shadcn-compatible context menu component for React, built on the radix-ui ContextMenu primitive and styled with Tailwind CSS v4. It opens on right-click over any target and covers the whole menu vocabulary in one install: plain actions, a danger variant for destructive items, checkbox items, radio groups, nested submenus, labels, separators and right-aligned shortcut hints.

Because it ships through the shadcn registry format, you install it with one CLI command, an MCP agent, or a copy-paste, and the source lands in your own project. You own the file; there is no runtime dependency on ai2 itself. The live example above is the exact component you get.

What is the ai2 Context Menu?

It is a composition around ContextMenu, ContextMenuTrigger and ContextMenuContent, with ContextMenuItem, ContextMenuCheckboxItem, ContextMenuRadioGroup and ContextMenuRadioItem for entries, plus label, separator, shortcut and the ContextMenuSub trio for nesting. The anatomy mirrors the ai2 Dropdown Menu, so the same item vocabulary applies; only the trigger differs.

On top of the radix API, items add two ai2 props: variant, where danger colors the item and its icons with the danger tone, and inset, which aligns plain items with checkbox and radio rows. The content portals to the body and animates from the pointer position where the menu opened.

Why use it

  • Right-click, done right: The radix-ui ContextMenu primitive replaces the native browser menu on the target, positions the menu at the pointer and handles long-press on touch, so contextual actions feel native without custom event code.
  • Accessible by construction: Menu roles, typeahead, focus management and dismissal come from radix: arrow keys move, Enter selects, Escape closes and focus returns to the trigger.
  • Danger items built in: variant="danger" styles destructive actions like Delete with the danger token, including their icons and a soft danger highlight on focus, no custom classes needed.
  • Stateful items included: Checkbox items with check indicators and exclusive radio groups with dot indicators ship in the same file, so view toggles and sort pickers need no extra components.
  • Agent-readable metadata: The registry item describes its parts and intended use in plain words, so an MCP agent can find, inspect and install it without guessing.

Features

  • shadcn registry install: One command adds the component, its dependencies and the @ai2/tokens theme to your project.
  • Pointer-anchored menu: The content opens at the cursor and portals to the body, so the menu never clips inside a scroll container or an overflow-hidden card.
  • Origin-aware animation: Open and close fade and zoom from the menu origin using the radix transform-origin variable, and item highlights run on the --motion-fast token.
  • Labels, separators and shortcuts: ContextMenuLabel titles a section, ContextMenuSeparator splits groups, and ContextMenuShortcut right-aligns a keyboard hint inside any item.
  • Submenus included: ContextMenuSub with ContextMenuSubTrigger and ContextMenuSubContent gives hover and keyboard-openable nested menus with a chevron indicator.
  • Data attributes for styling: Every part exposes data-slot, items expose data-variant, and radix adds data-state and data-disabled, so any state is targetable from CSS.

Production tips

  • Make the trigger the surface: ContextMenuTrigger is the right-click area itself, not a button. Wrap the card, row or canvas region you want the menu to belong to, and give it a size so there is something to click.
  • Put danger items last: Separate destructive actions with a ContextMenuSeparator and keep them at the bottom with variant="danger", so muscle memory never lands on Delete.
  • Match the on-page action: A context menu should offer the same actions the target already supports elsewhere. Do not hide the only path to an action behind a right-click, since it is not discoverable.
  • Keep submenus shallow: One level of nesting is scannable; two is a maze. If a submenu grows past roughly seven items, promote it to a dialog or a dedicated panel.
  • Mind checkbox item dismissal: By default the menu closes when a checkbox item is toggled. For multi-toggle panels, call event.preventDefault() in onSelect to keep it open.

Works with the rest of ai2

A context menu pairs naturally with a ai2 Table row or a ai2 Card as the right-click target, and ai2 Kbd caps inside shortcut hints. For a button-triggered version of the same menu vocabulary, reach for the ai2 Dropdown Menu.

A danger item usually leads to a confirmation: pair it with the ai2 Dialog for a hard confirm, or the ai2 Popover when you need arbitrary content rather than menu items. All of them share one token source and the same popover surface styling.

FAQs

Get new components in your inbox

Component drops, new themes and release notes. No spam, and you can unsubscribe from any email.

© 2026 ai2 design system · MIT licensed · Built with its own components