videorc/ui

Context Menu

A menu at the pointer on right-click or long press, with the same popup tier and 28 px items as Dropdown Menu.

Right-click the scene

Installation

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

Usage

import {
  ContextMenu,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuTrigger,
} from "@/components/ui/context-menu";
<ContextMenu>
  <ContextMenuTrigger>{sceneCard}</ContextMenuTrigger>
  <ContextMenuContent>
    <ContextMenuItem onClick={rename}>Rename…</ContextMenuItem>
  </ContextMenuContent>
</ContextMenu>

A right-click is a shortcut, never the only way in: every action in a context menu is also in the item's Dropdown Menu or on screen.

Anatomy

<ContextMenu>
  <ContextMenuTrigger />
  <ContextMenuContent>
    <ContextMenuLabel />
    <ContextMenuGroup>
      <ContextMenuItem>
        <ContextMenuShortcut />
      </ContextMenuItem>
    </ContextMenuGroup>
    <ContextMenuSeparator />
    <ContextMenuCheckboxItem />
    <ContextMenuRadioGroup>
      <ContextMenuRadioItem />
    </ContextMenuRadioGroup>
    <ContextMenuSub>
      <ContextMenuSubTrigger />
      <ContextMenuSubContent />
    </ContextMenuSub>
  </ContextMenuContent>
</ContextMenu>

Examples

Checkbox items

The Stream Manager's stats bar: right-click it to choose which stats show. Checkbox items keep the menu open.

ViewersBitrateUptime

Theming

Token or attributeMeaning
glass-floatThe popup tier: the window's solid tone, a 1 px rim and the float drop
rounded-lgThe popup tier's 10 px corners, with a 4 px inset
min-h-7, rounded-chip28 px items with 6 px corners
bg-accentThe highlighted item
data-variant="destructive"The destructive item's tone
select-noneOn the trigger, so a right-click doesn't select its text

Keyboard

KeyAction
ArrowDown, ArrowUpMoves between items
ArrowRight, ArrowLeftOpens or closes a submenu
Enter, SpaceChooses the highlighted item
EscapeCloses the menu

Accessibility

The menu opens from the pointer, so it has no keyboard path of its own; that is why its actions live somewhere else too. Like Dropdown Menu, it stops wheel events at its edge, and a ContextMenuLabel outside any group is a plain heading row.

API reference

Every Base UI Context Menu prop, plus:

ContextMenuContent

Prop

Type

ContextMenuItem

Prop

Type