Context Menu
Context Menu presents secondary actions at the pointer after a right click or long press.
Purpose
Context Menu presents secondary actions at the pointer after a right click or long press. Keep primary actions visible outside the menu.
Object actions
Installation
With the Siteplane registry alias configured, add the component and import the installed source from your app.
CLI
pnpm dlx shadcn@4.16.1 add @siteplane/context-menuImport
import { ContextMenu, ContextMenuCheckboxItem, ContextMenuGroup, ContextMenuGroupLabel, ContextMenuItem, ContextMenuLinkItem, ContextMenuPopup, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuSeparator, ContextMenuShortcut, ContextMenuSub, ContextMenuSubPopup, ContextMenuSubTrigger, ContextMenuTrigger } from "@/components/ui/context-menu";Need the machine-readable source metadata? View registry JSON.
Usage
Context Menu handles right-click actions for an object. Keep the trigger surface clear about what owns the menu.
import { ContextMenu, ContextMenuItem, ContextMenuPopup, ContextMenuTrigger } from "@/components/ui/context-menu";
export function Example() {
return (
<ContextMenu>
<ContextMenuTrigger render={<div />}>Right click target</ContextMenuTrigger>
<ContextMenuPopup><ContextMenuItem>Duplicate</ContextMenuItem></ContextMenuPopup>
</ContextMenu>
);
}Examples
Icons, groups, selection items, link items and submenus reuse the shared menu styling on a right-click surface.
With icons and shortcuts
Grouped
Checkbox items
Radio items
Switch items
variant="switch" stays a semantic checkbox item.
Link items
Router links use ContextMenuLinkItem with render instead of turning an item into a link.
Functional actions
API Reference
The reference lists the source-owned exports and props that are easy to miss in visual examples. Inherited Base UI props remain available unless the wrapper narrows them.
ContextMenuPopup widthaccepts"auto","trigger","content", or"at-least-trigger"; use the prop instead of hardcoded width classes.- Popup placement is controlled by
side,align,sideOffset, andalignOffset. Defaults are bottom, start, and zero side offset. - Use
inseton items, group labels, and submenu triggers to align rows without leading icons. ContextMenuCheckboxItem sizeaccepts"sm","default","lg", and"xl".- All item, selection, label, separator, and submenu rows inherit the provider
controlSize; repeated rows use the compact menu geometry from the global size contract rather than the 56px XL CTA height. ContextMenuLinkItem closeOnClickdefaults totrue; set it tofalseonly when navigation must leave the menu open.- Use
disabledfor unavailable actions. - Use
ContextMenuLinkItemfor navigation instead of adding link behavior to a command item.
Motion
Component motion uses the shared Siteplane motion contract. See the global motion guide for provider setup, tokens and reduced-motion behavior.
- Popup and submenu scale, fade, placement, and reduced-motion behavior are native to Context Menu.
- Active items and submenu triggers use a pointer cursor.
- Do not add a second popup transition.
Accessibility
- The trigger target needs visible context that explains what will receive the actions.
- Preserve right-click, long-press, keyboard, focus, Escape, and dismissal behavior.
- Keep disabled items unavailable and visibly distinct.
- Checkbox and radio items must retain their selection indicators.
Implementation Guidance
- Use Context Menu only for pointer-related secondary actions.
- Keep primary actions visible and discoverable elsewhere.
- Use width, placement, inset, size, disabled, and link props instead of local menu styling.
- Preserve native item, submenu, selection, cursor, and focus behavior.