nook
Browse the docs

Components

Context Menu

Built on Base UI

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

See the prompt
Q4 launch plan.pdfRight click, or long press on touch

Installation

npx nook-ui@latest add context-menu

Prompt

Paste this into your AI coding assistant. It adds this exact component, the same way the CLI does, and tells the assistant how to use it.

Short. For assistants that can run commands in your project.

Plain text
Add the Nook "Context Menu" component to this project, exactly as Nook ships it.

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

Steps
1. Check for `nook.json` in the project root. If it is missing, run `npx nook-ui@latest init` first (React or Next.js with Tailwind CSS v4). It adds the Nook tokens, the theme and `cn()`.
2. Run `npx nook-ui@latest add context-menu`. It writes `components/ui/context-menu.tsx` together with everything the component needs. Do not write the component from memory.
3. If you cannot run commands, fetch http://localhost:3000/r/context-menu.json, write every entry of `files` to the path it names, install the packages in `dependencies`, and repeat for each name in `registryDependencies`.
4. Use it where I ask. Start from this example:

```tsx
import {
  ContextMenu,
  ContextMenuCheckboxItem,
  ContextMenuContent,
  ContextMenuItem,
  ContextMenuSeparator,
  ContextMenuTrigger,
} from "@/components/ui/context-menu";

export default function ContextMenuDefault() {
  return (
    <ContextMenu>
      <ContextMenuTrigger
        tabIndex={0}
        className="flex h-32 w-full max-w-sm flex-col items-center justify-center gap-1 rounded-lg border border-dashed border-border bg-muted/40 text-sm"
      >
        <span className="font-medium">Q4 launch plan.pdf</span>
        <span className="text-muted-foreground">Right click, or long press on touch</span>
      </ContextMenuTrigger>
      <ContextMenuContent>
        <ContextMenuItem>Open</ContextMenuItem>
        <ContextMenuItem>Rename</ContextMenuItem>
        <ContextMenuItem>Copy link</ContextMenuItem>
        <ContextMenuCheckboxItem defaultChecked>Pinned</ContextMenuCheckboxItem>
        <ContextMenuSeparator />
        <ContextMenuItem destructive>Move to trash</ContextMenuItem>
      </ContextMenuContent>
    </ContextMenu>
  );
}
```

API
- `ContextMenu, ContextMenuTrigger, ContextMenuContent`: The root, the area that opens the menu, and the menu.
- `ContextMenuItem`: An action.
  - `destructive` (`boolean`): Style the item as a destructive action.
- `ContextMenuCheckboxItem, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuLabel, ContextMenuGroup, ContextMenuSeparator`: The same parts as Dropdown Menu.

Rules
- Colors, radii, shadows and motion come from Nook tokens and classes such as `bg-primary`, `text-muted-foreground`, `border-border`, `rounded-lg` and `h-control`. Never hard-code them.
- Do not restyle or simplify the file. Change how it looks through `className`, its props and the theme.
- It must keep working with the keyboard, in light and dark mode, and in the sharp, soft and bold styles.
- Accessibility: Opens on right click, long press, or the menu key (Shift F10) when the trigger has focus, so give the trigger `tabIndex={0}` if it is not focusable already. Arrow keys move, typing jumps to an item, Escape closes.

Done when the component renders like the example in light and dark mode and the project type-checks.

Usage

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

export default function ContextMenuDefault() {
  return (
    <ContextMenu>
      <ContextMenuTrigger
        tabIndex={0}
        className="flex h-32 w-full max-w-sm flex-col items-center justify-center gap-1 rounded-lg border border-dashed border-border bg-muted/40 text-sm"
      >
        <span className="font-medium">Q4 launch plan.pdf</span>
        <span className="text-muted-foreground">Right click, or long press on touch</span>
      </ContextMenuTrigger>
      <ContextMenuContent>
        <ContextMenuItem>Open</ContextMenuItem>
        <ContextMenuItem>Rename</ContextMenuItem>
        <ContextMenuItem>Copy link</ContextMenuItem>
        <ContextMenuCheckboxItem defaultChecked>Pinned</ContextMenuCheckboxItem>
        <ContextMenuSeparator />
        <ContextMenuItem destructive>Move to trash</ContextMenuItem>
      </ContextMenuContent>
    </ContextMenu>
  );
}

Examples

File list

  • Brand guidelines.pdf
  • Pitch deck v3.key
  • Budget 2026.xlsx

Canvas with groups

Right click anywhere on the board

Radio choice

Showing as list. Right click to change.

Text block

The kickoff is on Tuesday at 10:00. Bring the signed brief and the latest budget so we can confirm scope with the client.

Props

ContextMenu, ContextMenuTrigger, ContextMenuContent

The root, the area that opens the menu, and the menu.

ContextMenuItem

An action.

PropTypeDefaultDescription
destructiveboolean–Style the item as a destructive action.

ContextMenuCheckboxItem, ContextMenuRadioGroup, ContextMenuRadioItem, ContextMenuLabel, ContextMenuGroup, ContextMenuSeparator

The same parts as Dropdown Menu.

Accessibility

Opens on right click, long press, or the menu key (Shift F10) when the trigger has focus, so give the trigger `tabIndex={0}` if it is not focusable already. Arrow keys move, typing jumps to an item, Escape closes.

Checked against WCAG 2.1 AA with automated axe tests and keyboard tests on every release.