Skip to content
English

How it works

The menu opens to the right of and below the point, flips left or up when it would leave the area, and scales from the corner nearest the point. Coordinates are converted to layout pixels, so a scaled ancestor does not offset it. A long press shows a ring that closes under the finger and cancels if the finger moves more than 8px.

Use it for

  • Secondary actions on items in a grid, list or canvas.
  • Desktop-like apps where users expect right-click.

Look elsewhere when

  • The only way to reach an action: also offer a visible button.
  • Primary actions: show them directly.

Usage

import { ContextMenu } from './ContextMenu.jsx'

export function FileGrid({ files }) {
  return (
    <ContextMenu
      label="File actions"
      items={[
        { id: 'open', label: 'Open', shortcut: '↵', onSelect: open },
        { id: 'rename', label: 'Rename', onSelect: rename },
        { type: 'separator' },
        { id: 'trash', label: 'Move to trash', danger: true, onSelect: trash },
      ]}
    >
      {files.map((f) => <FileTile key={f.id} file={f} tabIndex={0} />)}
    </ContextMenu>
  )
}

Props

PropTypeDefaultWhat it does
childrenReactNode—The area that answers right-click and long press; it becomes the positioning context.
items({ id, label, icon?, shortcut?, danger?, disabled?, onSelect? } | { type: 'separator' } | { type: 'label', label })[]—Menu entries.
labelstring—Accessible name of the menu.
onOpen(target: Element) => void—Called with the element that was right-clicked or pressed, so you know what the menu is for.
onOpenChange(open: boolean) => void—Called when the menu opens or closes.
longPressnumber480Touch hold time in ms.
defaultOpenAt{ x, y } | nullnullOpen on first render at this point in the area (without taking focus).
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the area.

Accessibility

  • role menu with role menuitem rows and role separator; disabled items carry aria-disabled.
  • Shift+F10 or the Menu key on a focused element opens it with focus on the first item; Up, Down, Home, End and typeahead move; Enter chooses.
  • Escape or Tab closes the menu and returns focus to the element it was opened from; a click outside, scrolling or leaving the window also closes it.
  • Items are 34px high; the destructive item uses red text and an icon, not colour alone.
  • With reduced motion the menu fades without scaling and the long-press ring is shown without animating.

Motion

Menu 160ms cubic-bezier(0.2, 0.9, 0.3, 1.1) from 0.94 scale at the corner nearest the pointer; long-press ring fills linearly over the hold time.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

ContextMenu.jsxcontext-menu.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Overlays
Bottom sheet comes with Pro. Its preview shows once you unlock it.