Context Menu

The actions menu that opens where you right-click. Built on Radix ContextMenu for keyboard navigation and a11y; it shares its surface and density with Dropdown Menu, but anchors to the cursor.

Q3 Marketing Plan
Edited 2 hours ago · 14 files

Right-click to open the menu

Installation#

# One-time setup (tokens + lib helpers)npx koalaui-cli@latest init# Add this component (its dependencies come along)npx koalaui-cli@latest add context-menu

Usage#

usage.tsxTSX
import {  ContextMenu, ContextMenuTrigger, ContextMenuContent,  ContextMenuItem, ContextMenuSeparator, ContextMenuShortcut,} from "@/components/ui/context-menu"import { Card } from "@/components/ui/card"import { Copy, PencilSimple, Trash } from "@phosphor-icons/react"export function Example() {  return (    <ContextMenu>      <ContextMenuTrigger asChild>        <Card className="w-72 select-none p-6">Right-click me</Card>      </ContextMenuTrigger>      <ContextMenuContent className="w-48">        <ContextMenuItem>          <PencilSimple /> Rename          <ContextMenuShortcut>⌘R</ContextMenuShortcut>        </ContextMenuItem>        <ContextMenuItem>          <Copy /> Duplicate          <ContextMenuShortcut>⌘D</ContextMenuShortcut>        </ContextMenuItem>        <ContextMenuSeparator />        <ContextMenuItem variant="destructive">          <Trash /> Delete        </ContextMenuItem>      </ContextMenuContent>    </ContextMenu>  )}

Any surface as the trigger#

Wrap any element with ContextMenuTrigger and asChild; the menu opens at the cursor anywhere inside it. An image is the classic right-click target.

Mountain landscape at dusk
Right-click the image

Checkbox items#

Toggle independent options straight from the menu. ContextMenuCheckboxItem keeps the menu open on click so several can be flipped in one pass.

Right-click the canvas

Switch items#

Pass variant="switch" to a checkbox item for an option that applies the moment it flips. The menu stays open when it is toggled, so a few can be set before it closes; the row is still a menu checkbox, with the switch as its drawing.

Right-click the canvas

Radio items#

A mutually exclusive choice lives in a ContextMenuRadioGroup with a shared value; the active row shows a check.

Right-click to sort

Groups, submenus & shortcuts#

Section items with ContextMenuGroup, nest a ContextMenuSub, and add right-aligned hints with ContextMenuShortcut (decorative; wire the real binding in your app). Use inset to align items that have no leading icon.

Right-click the editor

FAQ#

They share the same surface and items; the difference is how they open. A Dropdown Menu opens on click of a visible trigger button, so the affordance is obvious. A Context Menu opens on right-click (or long-press) of an arbitrary area like a card, row, image, or canvas, so it is best for secondary or power-user actions that should not take up button space. Many apps offer both: a more-actions button and the same actions on right-click.