ContextMenu

Right-click, long-press or press the Menu key for a menu that opens out of the exact point you pressed. It flips to stay on screen and moves with the arrow keys. Overlays.

Open playground

Right-click here, long-press on touch, or focus and press the Menu key.

About

ContextMenu is a React component in the Overlays category of smoui. It is typed, ships no stylesheet, follows your theme through CSS variables, and honors prefers-reduced-motion. Import it with import { ContextMenu } from "@ashutoshswamy/smoui" and set items, children.

Install

Terminal
npm i @ashutoshswamy/smoui

Usage

TSX
import { ContextMenu } from "@ashutoshswamy/smoui";

<ContextMenu
  items={[
    { label: "Open", hint: "Enter", onSelect: () => open() },
    { label: "Rename", hint: "F2", onSelect: () => rename() },
    { label: "Delete", danger: true, separated: true, onSelect: () => remove() },
  ]}
>
  <div className="p-10">Right-click me</div>
</ContextMenu>

Props 2

items

label, hint, onSelect, danger, disabled and separated (a divider above).

ContextMenuItem[]
children

The area that listens for the right-click. It is focusable, so the keyboard Menu key works.

ReactNode