Xzero UI
Pro library

Context menu

Secondary actions kept close to the selected object.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui/context-menu
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui/context-menu

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { ContextMenu } from "@/components/xzero/context-menu/context-menu";
import { Copy, Trash2 } from "lucide-react";

export function FileTile({ file }: { file: File }) {
  return (
    <ContextMenu
      label={`Actions for ${file.name}`}
      items={[
        { id: "copy", label: "Copy link", icon: <Copy size={15} />, onSelect: () => copyLink(file) },
        { id: "delete", label: "Delete file", icon: <Trash2 size={15} />, destructive: true, onSelect: () => remove(file) },
      ]}
    >
      <FilePreview file={file} />
    </ContextMenu>
  );
}

API reference

ContextMenu

Wraps content and opens a menu at the pointer on right-click, or under the target on click and keyboard.

PropTypeDefaultDescription
children (required)ReactNode–The target area.
items (required)ContextMenuItem[]–Items: { id, label, icon?, onSelect?, disabled?, destructive?, checked? }.
labelstring"Context menu"Accessible name for both the target and the menu.

Keyboard interactions

KeysAction
ContextMenu / Shift+F10Opens the menu under the focused target.
ArrowDown / ArrowUpMoves between enabled items, wrapping at the ends.
Home / EndJumps to the first or last enabled item.
Enter / SpaceSelects the focused item and closes the menu.
EscapeCloses the menu and returns focus to the target.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in menus

Guidance for AI tools

Context menu: Secondary actions kept close to the selected object. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components