# Context menu

A native-trigger context menu with bounded portal content, keyboard navigation, typeahead, action items and real link items.

Access: pro. Category: Navigation. Kind: composite.

## When to use

- Use it when a page needs a native-trigger context menu with bounded portal content, keyboard navigation, typeahead, action items and real link items.
- Choose it as the nav region when composing a page from independently reusable TidalUI sections.

## Alternatives

- Choose navigation-bar instead when responsive saas navigation with native links, actions and an in-flow mobile disclosure is the actual interface need, rather than context menu.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Context menu

```sh
npx shadcn@latest add @tidal-pro/context-menu
```

Stylesheets: `components/ui/tidal.css`, `components/ui/context-menu.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/context-menu.css";
import{TidalContextMenu}from"./components/ui/context-menu";
export default()=><div className="tidal-scope"><TidalContextMenu/></div>;
```

## Structured props

- `TidalContextMenu.theme?: MenuTheme | undefined` (default "light"): Optional theme value accepted by this exported component.
- `TidalContextMenuContent.portalContainer?: HTMLElement | null | undefined`: Optional portal container value accepted by this exported component.
- `TidalContextMenuItem.destructive?: boolean | undefined`: Optional destructive value accepted by this exported component.
- `TidalContextMenuLinkItem.anchorProps: Omit<Omit<DetailedHTMLProps<AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, "ref">, "children"> & { href: string; }`: Required anchor props value accepted by this exported component.
- `TidalContextMenuLinkItem.children: ReactNode`: Required children value accepted by this exported component.
- `TidalContextMenuLinkItem.destructive?: boolean | undefined`: Optional destructive value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/context-menu.tsx) | [Manifest](https://tidalui.com/examples/context-menu.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
"use client";

import "./components/ui/tidal.css";

import { useId, useState } from "react";

import { Archive, Copy, ExternalLink, FileText, FolderOpen, RotateCcw } from "lucide-react";

import { TidalContextMenu, TidalContextMenuContent, TidalContextMenuItem, TidalContextMenuLabel, TidalContextMenuLinkItem, TidalContextMenuSeparator, TidalContextMenuTrigger } from "./components/ui/context-menu";

import "./components/ui/context-menu.css";



const tidalExampleStyles = ".tidal-scope .context-menu-demo,\n.tidal-scope .context-menu-demo * {\n  box-sizing: border-box;\n}\n\n.tidal-scope .context-menu-demo {\n  container: tidal-context-demo / inline-size;\n  display: grid;\n  width: min(100%, 1040px);\n  min-width: 0;\n  gap: 24px;\n  margin-inline: auto;\n  padding: clamp(16px, 4vw, 44px);\n  color: var(--t-ink);\n}\n\n.tidal-scope .context-menu-demo-heading {\n  display: grid;\n  max-width: 660px;\n  min-width: 0;\n  gap: 8px;\n}\n\n.tidal-scope .context-menu-demo-heading :is(h2, p) {\n  margin: 0;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .context-menu-demo-heading h2 {\n  font-size: clamp(27px, 5vw, 44px);\n  font-weight: 570;\n  letter-spacing: -0.052em;\n  line-height: 1;\n}\n\n.tidal-scope .context-menu-demo-heading p {\n  color: var(--t-muted);\n  font-size: 12px;\n  line-height: 1.55;\n}\n\n.tidal-scope .context-menu-demo-shell {\n  display: grid;\n  grid-template-columns: minmax(0, 1.45fr) minmax(250px, 0.75fr);\n  min-width: 0;\n  border: 1px solid var(--t-border);\n  border-radius: 18px;\n  overflow: hidden;\n  background: var(--t-surface);\n  box-shadow:\n    inset 0 1px #ffffff0a,\n    0 18px 54px -42px #00000080;\n}\n\n.tidal-scope .context-menu-demo-list {\n  display: grid;\n  align-content: start;\n  min-width: 0;\n  max-height: 520px;\n  padding: 8px;\n  overflow: auto;\n  overscroll-behavior: contain;\n  scrollbar-width: thin;\n}\n\n.tidal-scope .context-menu-demo-file {\n  display: grid;\n  grid-template-columns: 42px minmax(0, 1fr) auto;\n  align-items: center;\n  width: 100%;\n  min-width: 0;\n  min-height: 68px;\n  gap: 12px;\n  padding: 10px 12px;\n  border: 1px solid transparent;\n  border-radius: 11px;\n  background: transparent;\n  color: var(--t-ink);\n  font: inherit;\n  text-align: start;\n  cursor: default;\n  transition:\n    background 180ms,\n    border-color 180ms,\n    transform 140ms var(--t-ease-out);\n}\n\n.tidal-scope .context-menu-demo-file:hover {\n  background: var(--t-subtle);\n}\n\n.tidal-scope .context-menu-demo-file[data-selected] {\n  border-color: var(--t-ink);\n  background: var(--t-wash);\n}\n\n.tidal-scope .context-menu-demo-file:active {\n  transform: scale(0.995);\n}\n\n.tidal-scope .context-menu-demo-file:focus-visible {\n  outline: 2px solid var(--t-ink);\n  outline-offset: -2px;\n}\n\n.tidal-scope .context-menu-demo-file-icon {\n  display: grid;\n  width: 42px;\n  height: 42px;\n  place-items: center;\n  border: 1px solid var(--t-border);\n  border-radius: 10px;\n  background: var(--t-surface);\n}\n\n.tidal-scope .context-menu-demo-file-copy {\n  display: grid;\n  min-width: 0;\n  gap: 4px;\n}\n\n.tidal-scope .context-menu-demo-file-copy strong,\n.tidal-scope .context-menu-demo-file-copy span,\n.tidal-scope .context-menu-demo-file-state {\n  min-width: 0;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .context-menu-demo-file-copy strong {\n  font-size: 13px;\n  font-weight: 620;\n}\n\n.tidal-scope .context-menu-demo-file-copy span,\n.tidal-scope .context-menu-demo-file-state {\n  color: var(--t-muted);\n  font-size: 11px;\n}\n\n.tidal-scope .context-menu-demo-file-state {\n  justify-self: end;\n  padding: 5px 7px;\n  border: 1px solid var(--t-border);\n  border-radius: 999px;\n  background: var(--t-surface);\n}\n\n.tidal-scope .context-menu-demo-details {\n  display: grid;\n  align-content: space-between;\n  min-width: 0;\n  gap: 28px;\n  padding: clamp(20px, 4vw, 34px);\n  border-inline-start: 1px solid var(--t-border);\n  background: var(--t-subtle);\n}\n\n.tidal-scope .context-menu-demo-details > div {\n  display: grid;\n  min-width: 0;\n  gap: 8px;\n}\n\n.tidal-scope .context-menu-demo-details :is(span, h3, p, dl, dt, dd) {\n  margin: 0;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .context-menu-demo-details span {\n  color: var(--t-muted);\n  font-size: 11px;\n  font-weight: 700;\n  letter-spacing: 0.1em;\n  text-transform: uppercase;\n}\n\n.tidal-scope .context-menu-demo-details h3 {\n  font-size: clamp(19px, 3vw, 28px);\n  font-weight: 570;\n  letter-spacing: -0.035em;\n  line-height: 1.05;\n}\n\n.tidal-scope .context-menu-demo-details p,\n.tidal-scope .context-menu-demo-details dd {\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.5;\n}\n\n.tidal-scope .context-menu-demo-details dl {\n  display: grid;\n  min-width: 0;\n  gap: 10px;\n}\n\n.tidal-scope .context-menu-demo-details dl > div {\n  display: grid;\n  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);\n  min-width: 0;\n  gap: 10px;\n  padding-top: 10px;\n  border-top: 1px solid var(--t-border);\n}\n\n.tidal-scope .context-menu-demo-details dt {\n  font-size: 11px;\n  font-weight: 650;\n}\n\n.tidal-scope .context-menu-demo-footer {\n  display: grid;\n  grid-template-columns: minmax(0, 1fr) auto;\n  align-items: center;\n  min-width: 0;\n  gap: 8px 16px;\n}\n\n.tidal-scope .context-menu-demo-footer :is(p, span) {\n  margin: 0;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .context-menu-demo-footer p {\n  font-size: 11px;\n}\n\n.tidal-scope .context-menu-demo-footer > span {\n  grid-column: 1 / -1;\n  color: var(--t-muted);\n  font-size: 11px;\n}\n\n.tidal-scope .context-menu-demo-footer button {\n  min-width: 44px;\n  min-height: 44px;\n  padding: 0 14px;\n  border: 1px solid var(--t-border);\n  border-radius: 10px;\n  background: var(--t-surface);\n  color: var(--t-ink);\n  font: inherit;\n  font-size: 11px;\n  font-weight: 620;\n  transition:\n    border-color 160ms,\n    transform 140ms var(--t-ease-out);\n}\n\n.tidal-scope .context-menu-demo-footer button:hover {\n  border-color: var(--t-ink);\n}\n\n.tidal-scope .context-menu-demo-footer button:active {\n  transform: translateY(1px);\n}\n\n.tidal-scope .context-menu-demo-footer button:focus-visible {\n  outline: 2px solid var(--t-ink);\n  outline-offset: 3px;\n}\n\n@container tidal-context-demo (max-width: 680px) {\n  .tidal-scope .context-menu-demo-shell {\n    grid-template-columns: minmax(0, 1fr);\n  }\n\n  .tidal-scope .context-menu-demo-details {\n    border-block-start: 1px solid var(--t-border);\n    border-inline-start: 0;\n  }\n}\n\n@container tidal-context-demo (max-width: 390px) {\n  .tidal-scope .context-menu-demo-file {\n    grid-template-columns: 42px minmax(0, 1fr);\n  }\n\n  .tidal-scope .context-menu-demo-file-state {\n    grid-column: 2;\n    justify-self: start;\n  }\n\n  .tidal-scope .context-menu-demo-footer {\n    grid-template-columns: minmax(0, 1fr);\n  }\n\n  .tidal-scope .context-menu-demo-footer button {\n    width: 100%;\n  }\n}\n\n@media (pointer: coarse) {\n  .tidal-scope .context-menu-demo-file,\n  .tidal-scope .context-menu-demo-footer button {\n    font-size: 16px;\n  }\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .tidal-scope .context-menu-demo-file,\n  .tidal-scope .context-menu-demo-footer button {\n    transition: none;\n  }\n\n  .tidal-scope .context-menu-demo-file:active,\n  .tidal-scope .context-menu-demo-footer button:active {\n    transform: none;\n  }\n}";

type DemoFile = {
  id: string;
  name: string;
  detail: string;
  archived: boolean;
};

const INITIAL_FILES: DemoFile[] = [
  {
    id: "launch-brief",
    name: "Launch brief.pdf",
    detail: "PDF · 2.4 MB · Edited today",
    archived: false,
  },
  {
    id: "release-notes",
    name: "Release notes.txt",
    detail: "Text · 18 KB · Edited yesterday",
    archived: false,
  },
  {
    id: "cover-study",
    name: "Cover study.png",
    detail: "Image · 4.8 MB · Edited Monday",
    archived: false,
  },
];

export function ContextMenuDemo({
  theme = "light",
}: {
  theme?: "light" | "dark";
}) {
  const demoId = useId().replace(/:/g, "");
  const headingId = `${demoId}-project-files`;
  const detailsId = `${demoId}-file-details`;
  const [files, setFiles] = useState(INITIAL_FILES);
  const [selectedId, setSelectedId] = useState(INITIAL_FILES[0].id);
  const [status, setStatus] = useState("Select a file to inspect its details.");
  const selectedFile = files.find((file) => file.id === selectedId) ?? files[0];

  function openDetails(file: DemoFile) {
    setSelectedId(file.id);
    setStatus(`${file.name} is selected in this preview.`);
  }

  function duplicate(file: DemoFile) {
    const copyNumber = files.filter((item) =>
      item.id.startsWith(`${file.id}-copy`),
    ).length;
    const extensionIndex = file.name.lastIndexOf(".");
    const base =
      extensionIndex > 0 ? file.name.slice(0, extensionIndex) : file.name;
    const extension = extensionIndex > 0 ? file.name.slice(extensionIndex) : "";
    const copy: DemoFile = {
      ...file,
      id: `${file.id}-copy-${copyNumber + 1}`,
      name: `${base} copy ${copyNumber + 1}${extension}`,
      archived: false,
    };
    setFiles((current) => [...current, copy]);
    setSelectedId(copy.id);
    setStatus(`${copy.name} was duplicated.`);
  }

  function toggleArchived(file: DemoFile) {
    const nextArchived = !file.archived;
    setFiles((current) =>
      current.map((item) =>
        item.id === file.id ? { ...item, archived: nextArchived } : item,
      ),
    );
    setStatus(
      `${file.name} is ${nextArchived ? "archived" : "active"} in this preview.`,
    );
  }

  return (
    <section className="context-menu-demo" aria-labelledby={headingId}>
      <header className="context-menu-demo-heading">
        <h2 id={headingId}>Project files</h2>
        <p>
          Right-click a row, long-press it, or use the keyboard context-menu
          command to open its actions.
        </p>
      </header>

      <div className="context-menu-demo-shell">
        <div
          className="context-menu-demo-list"
          aria-label="Sample project files"
        >
          {files.map((file, index) => (
            <TidalContextMenu key={file.id} theme={theme}>
              <TidalContextMenuTrigger
                className="context-menu-demo-file"
                data-selected={file.id === selectedId || undefined}
                onClick={() => openDetails(file)}
                aria-describedby={`${demoId}-${file.id}-meta`}
              >
                <span
                  className="context-menu-demo-file-icon"
                  aria-hidden="true"
                >
                  <FileText size={18} />
                </span>
                <span className="context-menu-demo-file-copy">
                  <strong>{file.name}</strong>
                  <span id={`${demoId}-${file.id}-meta`}>{file.detail}</span>
                </span>
                <span className="context-menu-demo-file-state">
                  {file.archived
                    ? "Archived"
                    : index === 0
                      ? "Recent"
                      : "Active"}
                </span>
              </TidalContextMenuTrigger>

              <TidalContextMenuContent aria-label={`Actions for ${file.name}`}>
                <TidalContextMenuLabel>{file.name}</TidalContextMenuLabel>
                <TidalContextMenuItem
                  textValue="Open details"
                  onSelect={() => openDetails(file)}
                >
                  <FolderOpen size={16} aria-hidden="true" />
                  <span className="tidal-context-item-copy">Open details</span>
                  <kbd aria-hidden="true">↵</kbd>
                </TidalContextMenuItem>
                <TidalContextMenuLinkItem
                  textValue="Jump to details"
                  anchorProps={{
                    href: `#${detailsId}`,
                    onClick: () => openDetails(file),
                  }}
                >
                  <ExternalLink size={16} aria-hidden="true" />
                  <span className="tidal-context-item-copy">
                    Jump to details
                  </span>
                </TidalContextMenuLinkItem>
                <TidalContextMenuItem
                  textValue="Duplicate"
                  onSelect={() => duplicate(file)}
                >
                  <Copy size={16} aria-hidden="true" />
                  <span className="tidal-context-item-copy">Duplicate</span>
                </TidalContextMenuItem>
                <TidalContextMenuSeparator />
                <TidalContextMenuItem
                  textValue={
                    file.archived ? "Restore to active" : "Archive in view"
                  }
                  destructive={!file.archived}
                  onSelect={() => toggleArchived(file)}
                >
                  {file.archived ? (
                    <RotateCcw size={16} aria-hidden="true" />
                  ) : (
                    <Archive size={16} aria-hidden="true" />
                  )}
                  <span className="tidal-context-item-copy">
                    {file.archived ? "Restore to active" : "Archive in view"}
                  </span>
                </TidalContextMenuItem>
                <TidalContextMenuItem
                  disabled
                  textValue="Move to client folder"
                >
                  <FolderOpen size={16} aria-hidden="true" />
                  <span className="tidal-context-item-copy">
                    Move to client folder
                  </span>
                </TidalContextMenuItem>
              </TidalContextMenuContent>
            </TidalContextMenu>
          ))}
        </div>

        <aside
          className="context-menu-demo-details"
          id={detailsId}
          aria-labelledby={`${detailsId}-title`}
        >
          <div>
            <span>Selected file</span>
            <h3 id={`${detailsId}-title`}>{selectedFile.name}</h3>
            <p>{selectedFile.detail}</p>
          </div>
          <dl>
            <div>
              <dt>View</dt>
              <dd>{selectedFile.archived ? "Archived" : "Active"}</dd>
            </div>
            <div>
              <dt>Location</dt>
              <dd>Project files</dd>
            </div>
          </dl>
        </aside>
      </div>

      <footer className="context-menu-demo-footer">
        <p role="status" aria-live="polite">
          {status}
        </p>
        <button
          type="button"
          onClick={() => {
            setFiles(INITIAL_FILES);
            setSelectedId(INITIAL_FILES[0].id);
            setStatus("Files reset.");
          }}
        >
          Reset sample
        </button>
        <span>Sample changes stay on this page.</span>
      </footer>
    </section>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <ContextMenuDemo />
    </div>
  );
}

```

## Gotchas

- The host application owns data, validation, persistence, navigation, and service side effects described by this API.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation.","Escape dismisses the open overlay where the underlying primitive supports dismissal."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

TidalContextMenu forwards optional open/onOpenChange state, direction and modal behavior while adding an explicit light/dark portal theme. When open is omitted, Radix manages trigger-driven open state; there is no defaultOpen prop. TidalContextMenuTrigger always renders a 44px native type=button with forwarded attributes/ref; disabled or aria-disabled true resolve native disabled behavior and explicit false is preserved. TidalContextMenuContent forwards Radix content attributes/ref, loop, collision, Escape, outside and autofocus contracts; its optional portalContainer remains consumer-owned. The trigger adds caller-preventable native ContextMenu and Shift+F10 keyboard opening. Radix supplies pointer/long-press opening, keyboard focus movement, typeahead, dismissal and trigger focus return. TidalContextMenuItem forwards action item attributes/ref, disabled, textValue and caller-preventable onSelect. TidalContextMenuLinkItem renders a real consumer-owned anchor, forwards its native attributes/ref, preserves modified/download/target navigation, and resolves either item disabled or anchorProps aria-disabled true before any consumer click handler while preserving explicit false. Label and Separator forward native primitive attributes/refs. Consumers own every action, route and state change; the component performs no file, network, storage or backend operation.
