CraftUI

Context Menu

A menu that opens where you right-click or long press.

Right-click this screenshot

Installation

npx shadcn@latest add @runqora/craft-context-menu

Usage

import {
  ContextMenu,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuTrigger,
} from "@/components/craft/context-menu";

<ContextMenu>
  <ContextMenuTrigger tabIndex={0}>Right-click here</ContextMenuTrigger>
  <ContextMenuContent>
    <ContextMenuItem>Open</ContextMenuItem>
    <ContextMenuItem variant="destructive">Delete</ContextMenuItem>
  </ContextMenuContent>
</ContextMenu>;

Props

ContextMenu

Prop

Type

Accessibility

  • Right-click, or a long press on a touch screen, opens the menu at the pointer.
  • From the keyboard, the context menu key or Shift+F10 opens it while focus is inside the trigger. Give the trigger tabIndex={0} if nothing in it can take focus.
  • Inside, it works like a Dropdown Menu: the arrow keys move, Right Arrow opens a submenu and Escape closes.
  • Anything in a context menu should also be reachable another way, as many people never right-click.

Customization

The items are Dropdown Menu's, renamed, so a context menu has the same groups, checkbox and radio items, submenus and destructive actions.

Dependencies

Source

On this page