Skip to content
synccn

Context Menu

Right-click menu that also opens on long-press.

Right-click here, or long-press on touch

Installation

$ pnpm dlx shadcn@latest add @synccn/context-menu

First time in this project? Connect synccn with one command.

Usage

import { ContextMenu } from "@/components/ui/context-menu";<ContextMenu items={items}>…</ContextMenu>

API reference

Generated from the component's TypeScript types, so it always matches the code.

ContextMenu

Right-click (or long-press) menu. items use the same shape as DropdownMenu.

  • itemsrequired
    ContextMenuItem[]

    Menu entries.

  • children
    React.ReactNode

    Content to render.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseClickOutside (closes on an outside click), useEscape (closes on Escape)

npm packages

Keyboard

  • EscClose the menu

Accessibility

  • Opens on right-click or long-press. Offer the same actions somewhere visible too, since context menus are hard to discover.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA roles: menu, menuitem
  • Closes with Escape
  • Closes when you click or tap outside
  • Shows a visible focus ring for keyboard users