---
title: "Context Menu"
description: "A contextual action menu available by right-click or keyboard."
---

Interactive preview: https://ui.coderocket.app/docs/components/context-menu

## Usage

Get this component from a [saved library export](/docs/export) or the [connected CLI](/docs/agents). The imports below refer to local files installed in your app.

Import `styles/components.css`, then `styles/theme.css` once. Wrap your app in `ThemeScope` from `components/ui/utils` so typography, focus and overlays share the theme. The [installation guide](/docs/export) covers runtime dependencies and React/Next.js setup.

```tsx
import { ContextMenu } from './components/ui/context-menu';

<ContextMenu items={[{label:"Open",onSelect:()=>console.info("Open")},{label:"Duplicate",onSelect:()=>console.info("Duplicate")}]}>Right-click here, or press Shift + F10.</ContextMenu>
```

## Design system

This component consumes your semantic colors, spacing, typography and shape tokens. Import the compiled styles and your theme once as described in [Export](/docs/export).

Dependencies: [Dropdown](/docs/components/dropdown).

## Behavior and accessibility

- Provide meaningful labels for interactive controls.
- Connect action callbacks to your application logic.
- Verify keyboard navigation and contrast in your application.

Status: **experimental** during early access. Sample previews do not send emails, process payments or upload files to a service.

## Source and props

This is the exported source, using the same implementation as the editor.

```tsx
"use client";
import { ContextMenu as Base } from "@base-ui/react/context-menu";
import { Menu } from "@base-ui/react/menu";
import type { ComponentProps, ReactNode } from "react";
import type { MenuAction } from "./dropdown";
import { usePortalContainer } from "./utils";
export function ContextMenu({
  children,
  items,
  emptyMessage = "No actions available.",
  ...rootProps
}: Omit<ComponentProps<typeof Base.Root>, "children"> & {
  children: ReactNode;
  items: MenuAction[];
  emptyMessage?: ReactNode;
}) {
  const container = usePortalContainer();
  return (
    <Base.Root {...rootProps}>
      <Base.Trigger className="cr-context-trigger" tabIndex={0}>
        {children}
      </Base.Trigger>
      <Menu.Portal container={container}>
        <Menu.Positioner className="cr-positioner">
          <Menu.Popup className="cr-popup">
            {!items.length && <p className="cr-description">{emptyMessage}</p>}
            {items.map((item, index) => (
              <Menu.Item
                key={item.id ?? index}
                render={
                  item.href && !item.disabled ? (
                    <a href={item.href}>{item.label}</a>
                  ) : undefined
                }
                className="cr-menu-item"
                data-destructive={item.destructive || undefined}
                disabled={item.disabled}
                onClick={item.onSelect}
              >
                {item.label}
              </Menu.Item>
            ))}
          </Menu.Popup>
        </Menu.Positioner>
      </Menu.Portal>
    </Base.Root>
  );
}
```
