Context Menu
A zero-dependency right-click context menu anchored to cursor coordinates, with an origin-aware reveal, spring-gliding item highlight, stroke-draw checkboxes, and keyboard navigation.
Customize
Installation
npx shadcn@latest add @kinetic/context-menuUsage
Wrap a region in ContextMenuTrigger. Right-clicking inside it opens ContextMenuContent at the pointer position. The ContextMenu key or Shift+F10 opens it from the keyboard, centered on the focused trigger, with the first item focused.
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuSeparator,
ContextMenuShortcut,
ContextMenuTrigger,
} from "@/components/kinetic/ui/context-menu";
export function CanvasArea() {
return (
<ContextMenu>
<ContextMenuTrigger className="grid h-40 place-items-center rounded-lg border">
Right-click here
</ContextMenuTrigger>
<ContextMenuContent>
<ContextMenuItem>
Copy <ContextMenuShortcut>Ctrl+C</ContextMenuShortcut>
</ContextMenuItem>
<ContextMenuSeparator />
<ContextMenuItem variant="destructive">Delete</ContextMenuItem>
</ContextMenuContent>
</ContextMenu>
);
}Trigger options
ContextMenuTrigger accepts disabled, asChild to render your own element, and longPressDelay to set how long a touch must be held before the menu opens (default 500 ms, clamped between 200 and 1500, and 0 disables long press).
<ContextMenuTrigger asChild longPressDelay={600}>
<section>...</section>
</ContextMenuTrigger>Positioning
The menu is anchored to the cursor coordinates and its reveal grows from the anchored corner. Use collisionPadding on ContextMenu or ContextMenuContent to keep the menu away from the viewport edges.
Portal
ContextMenuContent portals to document.body by default. Wrap it in ContextMenuPortal with a container prop when mounting inside a specific DOM node without creating a duplicate portal.
import {
ContextMenu,
ContextMenuContent,
ContextMenuItem,
ContextMenuPortal,
ContextMenuTrigger,
} from "@/components/kinetic/ui/context-menu";
<ContextMenu>
<ContextMenuTrigger>Right-click</ContextMenuTrigger>
<ContextMenuPortal container={portalContainer}>
<ContextMenuContent>
<ContextMenuItem>Inspect</ContextMenuItem>
</ContextMenuContent>
</ContextMenuPortal>
</ContextMenu>Items
ContextMenuItem supports variant (default or destructive), inset, disabled, closeOnSelect and onSelect. Use ContextMenuLabel, ContextMenuGroup and ContextMenuSeparator to organize them.
<ContextMenuItem inset onSelect={() => rename()}>
Rename
</ContextMenuItem>Checkbox and radio items
ContextMenuCheckboxItem takes checked with onCheckedChange, or defaultChecked. Wrap ContextMenuRadioItem elements, each with a value, in a ContextMenuRadioGroup.
<ContextMenuCheckboxItem checked={showHidden} onCheckedChange={setShowHidden}>
Show hidden files
</ContextMenuCheckboxItem>
<ContextMenuRadioGroup value={sort} onValueChange={setSort}>
<ContextMenuRadioItem value="name">Name</ContextMenuRadioItem>
<ContextMenuRadioItem value="date">Date</ContextMenuRadioItem>
</ContextMenuRadioGroup>Submenus
Nest ContextMenuSub, ContextMenuSubTrigger and ContextMenuSubContent inside the content.
<ContextMenuSub>
<ContextMenuSubTrigger>Share</ContextMenuSubTrigger>
<ContextMenuSubContent>
<ContextMenuItem>Copy link</ContextMenuItem>
</ContextMenuSubContent>
</ContextMenuSub>Motion preferences
Tune the animation with speed, stiffness, damping and blurPx on ContextMenu. Timing follows the current Kinetic tempo, and motion is simplified when reduced motion is enabled.
API Reference
ContextMenu
Zero-dependency context menu root managing pointer coordinates, open state, and spring highlight physics.
| Prop | Type | Default | Description |
|---|---|---|---|
durationMs | number | 170 | Base reveal duration in milliseconds. |
speed | number | 1 | Playback speed multiplier for reveal and highlight spring. |
stiffness / damping | number | 420 / 32 | Spring parameters controlling highlight tracking. |
collisionPadding | number | 8 | Viewport edge margin in pixels used for auto corner flipping. |
ContextMenuTrigger / ContextMenuContent
Right-click / Shift+F10 target area and portaled floating menu anchored to the cursor corner.
| Prop | Type | Default | Description |
|---|---|---|---|
disabled (ContextMenuTrigger) | boolean | false | Prevents opening the context menu on secondary click. |
asChild (ContextMenuTrigger) | boolean | false | Merges context-menu listeners onto the child element. |
ContextMenuPortal
Optional explicit portal wrapper controlling where ContextMenuContent mounts.
| Prop | Type | Default | Description |
|---|---|---|---|
container | Element | null | document.body | DOM target element for portaled menu content. |