Context Menu

The menu behind a right-click, a long press or Shift+F10, with submenus that don't snap shut.

Category
Overlays
Access
Free with an account
Source
382 lines · one file
States
6 drawn
Added
3 Nov 2026

The decision inside it

It never opens off screen, and diagonal moves keep the submenu

Near an edge it flips to the other side of the pointer, and a submenu that won't fit on the right opens on the left. While the pointer travels inside the triangle toward an open submenu, the rows it crosses are ignored, so the submenu stays open.

When to use it

Use Context Menu on things people act on in place: files, rows, cards, canvas objects. For a menu behind a visible button, use Dropdown Menu.

Installation

How you get it

Paste this into Claude Code, Cursor, Codex or any coding agent. It installs the file and uses it as it is, instead of writing a new one.

Use Liro's Context Menu for this.
Install it: npx shadcn@latest add @liro/context-menu
(the @liro registry is set up in components.json, with LIRO_KEY in .env.local)
Import it from @/components/ui/context-menu.
Do not rewrite or restyle it. Pass my data through its props
and keep its built-in states.

For the full brief with every prop and the mistakes assistants usually make, use Copy prompt above. Free components install through the @liro registry with your CLI token: see the Namespaced tab.

Usage

components/file-row.tsx
import { Copy, PenLine, Trash2 } from "lucide-react";
import { ContextMenu, type ContextMenuItem } from "@/components/ui/context-menu";

export function FileRow({ name, onRename, onDuplicate, onDelete }: {
  name: string;
  onRename: () => void;
  onDuplicate: () => void;
  onDelete: () => void;
}) {
  const items: ContextMenuItem[] = [
    { id: "rename", label: "Rename", icon: <PenLine />, shortcut: "F2", onSelect: onRename },
    { id: "duplicate", label: "Duplicate", icon: <Copy />, shortcut: "⌘D", onSelect: onDuplicate },
    { type: "separator" },
    { id: "delete", label: "Delete", icon: <Trash2 />, destructive: true, onSelect: onDelete },
  ];
  return (
    <ContextMenu items={items}>
      <div tabIndex={0} className="rounded-lg px-3 py-2 hover:bg-muted">{name}</div>
    </ContextMenu>
  );
}

API reference

“Copy prompt” above puts a full brief on your clipboard, install command, dependencies, props, and the mistakes an assistant usually makes with this component.

Props

Read from the component’s own TypeScript interface when the site is built, so this table cannot drift from the file you install.

TypeNotes
itemsContextMenuItem[] Yes–
onAction(id: string) => void NoCalled with the id of any item chosen, after its own onSelect.
disabledboolean NoTurn the menu off (for example while a row is being edited).
childrenReact.ReactNode Yes–

Dependencies

npm packages

clsxframer-motionlucide-reacttailwind-merge

Liro foundations, installed alongside it

liro-theme

States

All of them are drawn by the component. None is left for you to design.

  • Closed
  • Open
  • Submenu
  • Checkbox
  • Destructive
  • Keyboard

Accessibility

  • Keyboard reachable throughout, in visual order
  • Focus trapped in overlays, Escape closes them
  • Focus returns to whatever opened it
  • Live regions announce what changed, not that something did
  • Honours prefers-reduced-motion

Responsive behavior

  • Sizes to its container, not the viewport
  • Usable from 320px up
  • Pointer-based interaction, so trackpad and touch both work
  • No hover-only affordances