Skip to content
Back to skills

Takeoff Context Menu

ASecurity

`ContextMenu` opens an action menu where the user right-clicks, holds a touch (500 ms) or presses `Shift+F10` / the ContextMenu key inside an area, placed at the pointer. Behavior is Spar's `ContextMenu`, which shares `DropdownMenu`'s menu model; the items, keyboard and look are `Dropdown`'s. **When to use:** secondary actions on an object the user points at (a file, a row, a card, a canvas). Not this — a menu opened by clicking a button is `Dropdown`; a primary action needs a visible control...

  • 3 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added December 4, 2026
developmentreact

Works with

  • cli

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned December 4, 2026

npx -y skills add turkishtechnology/takeoff-v2 --skill takeoff-context-menu --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Takeoff Context Menu?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Takeoff Context Menu
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/turkishtechnology-takeoff-context-menu/badge)](https://www.skillsdirectory.com/skills/turkishtechnology-takeoff-context-menu)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: takeoff-context-menu
description:
  'Build a ContextMenu (an action menu opened by right-click, touch long-press
  or Shift+F10 on an area, placed at the pointer) — the ContextMenu from
  @takeoff-ui/react-spar (Takeoff UI / Spar React). Trigger when adding a
  right-click menu to a row, card, file, canvas or table cell, a long-press menu
  on touch, or replacing a hand-rolled onContextMenu handler. Use this skill
  WHENEVER building, adding, importing, styling, or fixing a ContextMenu in a
  React app that uses @takeoff-ui/react-spar / Takeoff / Spar. Not for a menu
  opened by a button — use Dropdown there.'
---

# ContextMenu — @takeoff-ui/react-spar

`ContextMenu` opens an action menu where the user right-clicks, holds a touch
(500 ms) or presses `Shift+F10` / the ContextMenu key inside an area, placed at
the pointer. Behavior is Spar's `ContextMenu`, which shares `DropdownMenu`'s
menu model; the items, keyboard and look are `Dropdown`'s.

**When to use:** secondary actions on an object the user points at (a file, a
row, a card, a canvas). Not this — a menu opened by clicking a button is
`Dropdown`; a primary action needs a visible control. Keep every context-menu
action reachable another way too: right-click is a convention, not a visible
affordance.

## Setup

Requires the Takeoff provider + token CSS mounted once at the app root (see the
`takeoff-ui` skill or the installation docs). Then import:

```tsx
import { ContextMenu } from '@takeoff-ui/react-spar';
```

## Compound parts

- `ContextMenu` — root; state only, renders no DOM. Holds `size`, `open` /
  `defaultOpen` / `onOpenChange`, `modal`, `disabled`, `closeOnSelect`.
- `ContextMenu.Trigger` — the area (a `div`, polymorphic via `as`). It gets no
  role; it is your content.
- `ContextMenu.Content` — the panel (`role="menu"`). Name it with `aria-label`.
  Render it beside the trigger, not inside it.
- `ContextMenu.Item` / `.Group` / `.Label` / `.Separator` / `.Viewport` — these
  **are** `Dropdown.Item` / `.Group` / `.Label` / `.Separator` / `.Viewport`
  (same props, `tk-dropdown-*` classes and theme keys).

## Basic usage

```tsx
<ContextMenu>
  <ContextMenu.Trigger className="file-row">report.pdf</ContextMenu.Trigger>
  <ContextMenu.Content aria-label="File actions">
    <ContextMenu.Item onSelect={openFile}>Open</ContextMenu.Item>
    <ContextMenu.Item onSelect={rename}>Rename</ContextMenu.Item>
    <ContextMenu.Separator />
    <ContextMenu.Item disabled>Delete</ContextMenu.Item>
  </ContextMenu.Content>
</ContextMenu>
```

## Examples

### Groups and a long list

```tsx
<ContextMenu size="small">
  <ContextMenu.Trigger>Seat 12A</ContextMenu.Trigger>
  <ContextMenu.Content aria-label="Seat actions">
    <ContextMenu.Group>
      <ContextMenu.Label>Seat</ContextMenu.Label>
      <ContextMenu.Item>Select seat</ContextMenu.Item>
    </ContextMenu.Group>
    <ContextMenu.Group>
      <ContextMenu.Label>Passenger</ContextMenu.Label>
      <ContextMenu.Viewport>
        {passengers.map(p => (
          <ContextMenu.Item key={p.id}>Assign to {p.name}</ContextMenu.Item>
        ))}
      </ContextMenu.Viewport>
    </ContextMenu.Group>
  </ContextMenu.Content>
</ContextMenu>
```

### Keyboard-reachable area, controlled

An area with no control of its own needs `tabIndex={0}` and an `aria-label` so
`Shift+F10` can reach it.

Note: `import { useState } from 'react';`

```tsx
const [open, setOpen] = useState(false);

<ContextMenu open={open} onOpenChange={setOpen}>
  <ContextMenu.Trigger tabIndex={0} aria-label="Seat map">
    <SeatMap />
  </ContextMenu.Trigger>
  <ContextMenu.Content aria-label="Seat map actions">
    <ContextMenu.Item>Zoom to fit</ContextMenu.Item>
  </ContextMenu.Content>
</ContextMenu>;
```

### Let the browser menu through for a text selection

A handler on the trigger runs first; `preventDefault()` keeps the menu closed
for that event (and the browser's own menu then shows):

```tsx
<ContextMenu.Trigger
  onContextMenu={event => {
    if (window.getSelection()?.toString()) event.preventDefault();
  }}
>
  …
</ContextMenu.Trigger>
```

## Key props

### `ContextMenu` (root)

| Prop            | Type                           | Default  | Notes                                                |
| --------------- | ------------------------------ | -------- | ---------------------------------------------------- |
| `size`          | `'small' \| 'base' \| 'large'` | `'base'` | Panel and item scale.                                |
| `open`          | `boolean`                      | -        | Controlled open state.                               |
| `defaultOpen`   | `boolean`                      | `false`  | Uncontrolled initial state.                          |
| `onOpenChange`  | `(open: boolean) => void`      | -        | Fires on open and close.                             |
| `modal`         | `boolean`                      | `true`   | Keeps focus inside the open menu.                    |
| `disabled`      | `boolean`                      | `false`  | The area does nothing; the browser's own menu shows. |
| `closeOnSelect` | `boolean`                      | `true`   | Close after an item is selected.                     |

### `ContextMenu.Content`

| Prop                                                          | Type                                     | Default   | Notes                                   |
| ------------------------------------------------------------- | ---------------------------------------- | --------- | --------------------------------------- |
| `side`                                                        | `'top' \| 'right' \| 'bottom' \| 'left'` | `'right'` | Side of the pointer the panel opens on. |
| `align`                                                       | `'start' \| 'center' \| 'end'`           | `'start'` | Alignment against the pointer.          |
| `sideOffset`                                                  | `number`                                 | `2`       | Distance in px from the pointer.        |
| `container`                                                   | `HTMLElement \| null`                    | body      | Portal container.                       |
| `onEscapeKeyDown` / `onPointerDownOutside` / `onFocusOutside` | event callbacks                          | -         | `preventDefault()` keeps the menu open. |

Items: `disabled`, `onSelect(event)` (`preventDefault()` keeps the menu open),
`textValue` (typeahead text for non-text children) — Dropdown's.

Full props, events, data attributes & type definitions: see
`references/full-docs.md`.

## Accessibility

- The panel is `role="menu"` with no `aria-labelledby`: always give
  `ContextMenu.Content` an `aria-label`.
- Pointer opening focuses the panel with nothing highlighted; `Shift+F10` / the
  ContextMenu key highlights the first item. `↓`/`↑` move and wrap, `Home` /
  `End` jump, `Enter` / `Space` select, typing jumps by typeahead, `Esc` closes.
  Focus returns to the element focused before opening.
- A touch or pen press held 500 ms opens it (iOS has no `contextmenu` event);
  the area sets `-webkit-touch-callout: none`.

## Reference

- Full component docs (Copy page): `references/full-docs.md`
- Live docs: https://v2.takeoffui.com/docs/components/context-menu
- Source: `packages/react-spar/src/components/context-menu/`
- Spar primitive: https://v2.takeoffui.com/headless/docs/Components/ContextMenu

Files in this skill

  • SKILL.md7.3 KB
  • references/full-docs.md16.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.