Navigation

Table Row Menu

A context menu for a table row: the row takes focus and a highlight, and the call works both with the mouse and with the menu key, which carries no cursor coordinates.

  • contextmenu
  • table
  • row
  • keyboard

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/contextmenu-006?lang=en

March invoices · правый клик по строке или Shift+F10
КлиентСтатусСумма
ООО «Полдень»Оплачен84 000 ₽
Ирина КовалёваЖдёт оплаты12 500 ₽
Студия «Круг»Черновик31 200 ₽
Show the full instructions

What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.

# Install and place "contextmenu-006" (Table Row Menu) from VibeUI

## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/contextmenu-006.json

Registry item: https://vibeui.ru/r/contextmenu-006.json
Installs to: components/vibeui/contextmenu-006.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.

Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.

## 2. What it is
A context menu for a table row: the row takes focus and a highlight, and the call works both with the mouse and with the menu key, which carries no cursor coordinates.

A table row context menu that highlights its target and opens from the keyboard: with zero coordinates it lands at the row's edge. One file, zero dependencies.

## 3. How to use it
import { Contextmenu006 } from "@/components/vibeui/contextmenu-006"

<Contextmenu006
  caption="March invoices"
  rows={[{ name: "Polden LLC", status: "Paid", sum: "84 000 ₽" }]}
/>

Read the installed file for the full prop list.

## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.

Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)

## 5. Keep exactly as installed
- the local --vibeui-contextmenu-006-* palette: the component must look the same in any project
- the zero-coordinate branch: the menu key and Shift+F10 carry no cursor position, and the menu would fly into the corner
- tabIndex and aria-selected on the row — without focus on the row there is no keyboard call
- the row highlight while the menu is open: in a twenty-row table "delete" without a visible target is roulette
- the row name in the menu header — it confirms what the commands apply to
- the component's own light surface: on the dark catalog card dark text disappears

## 6. You may change
- the table caption through caption
- the rows through rows
- the highlight and focus colour through accent
- the command list directly in the ACTIONS table

## 7. Rules
- A row with tabIndex joins the tab order: on a long table consider a roving tabindex.
- The menu does not flip at the bottom edge — add your own clamp if the table is long.
- Every command closes the menu: bulk actions need a different, non-per-row component.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.

## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.

For developers

npx shadcn@latest add https://vibeui.ru/r/contextmenu-006.json
https://vibeui.ru/r/contextmenu-006.json

Один файл, ноль зависимостей, палитра --vibeui-contextmenu-006-*. Клиентский: текущая строка и координаты держит useState. Строки получают tabIndex и aria-selected, подсветка живёт, пока открыт popover, и гаснет на событии toggle. Клавиша вызова меню и Shift+F10 приходят тем же событием contextmenu, но с нулевыми координатами — при них меню встаёт по левому нижнему краю самой строки, а не в углу экрана. Меню — HTML popover, поэтому Escape и клик мимо от браузера; в шапке имя строки, удаление отделено линией и покрашено текстом.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

"use client"

import { useRef, useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties, MouseEvent } from "react"

export type Contextmenu006Row = {
  name: string
  status: string
  sum: string
}

export type Contextmenu006Props = Omit<
  ComponentPropsWithoutRef<"section">,
  "children"
> & {
  caption?: string
  rows?: Contextmenu006Row[]
  accent?: string
}

// Идея компонента: контекстное меню строки таблицы. Строка получает tabindex и
// подсветку, пока меню открыто: в таблице из двадцати строк «удалить» без
// видимой цели — это рулетка. Клавиша вызова меню и Shift+F10 приходят тем же
// событием contextmenu, но без координат курсора, поэтому при нулевых
// координатах меню встаёт по краю самой строки, а не в углу экрана.
const STYLES = `
:where([data-vibeui-block="contextmenu-006"]){
--vibeui-contextmenu-006-bg:oklch(1 0 0);
--vibeui-contextmenu-006-fg:oklch(0.24 0.014 265);
--vibeui-contextmenu-006-muted:oklch(0.55 0.014 265);
--vibeui-contextmenu-006-border:oklch(0.9 0.006 265);
--vibeui-contextmenu-006-hover:oklch(0.97 0.003 265);
--vibeui-contextmenu-006-accent:oklch(0.55 0.18 250);
--vibeui-contextmenu-006-danger:oklch(0.56 0.19 25);
--vibeui-contextmenu-006-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
--vibeui-contextmenu-006-x:50%;
--vibeui-contextmenu-006-y:50%;
}
[data-vibeui-block="contextmenu-006"]{
display:block;width:100%;max-width:26rem;box-sizing:border-box;
background:var(--vibeui-contextmenu-006-bg);color:var(--vibeui-contextmenu-006-fg);
border:1px solid var(--vibeui-contextmenu-006-border);border-radius:0.875rem;
font-family:var(--vibeui-contextmenu-006-font);overflow:hidden;
}
[data-vibeui-block="contextmenu-006"] table{width:100%;border-collapse:collapse;font-size:0.8125rem}
[data-vibeui-block="contextmenu-006"] caption{
padding:0.625rem 0.875rem;text-align:left;
font-size:0.75rem;color:var(--vibeui-contextmenu-006-muted);
border-bottom:1px solid var(--vibeui-contextmenu-006-border);
}
[data-vibeui-block="contextmenu-006"] th{
padding:0.5rem 0.875rem;text-align:left;font-size:0.6875rem;font-weight:650;
letter-spacing:0.04em;text-transform:uppercase;color:var(--vibeui-contextmenu-006-muted);
border-bottom:1px solid var(--vibeui-contextmenu-006-border);
}
[data-vibeui-block="contextmenu-006"] td{
padding:0.5rem 0.875rem;border-bottom:1px solid var(--vibeui-contextmenu-006-border);
}
[data-vibeui-block="contextmenu-006"] tbody tr:last-child td{border-bottom:0}
[data-vibeui-block="contextmenu-006"] tbody tr{touch-action:manipulation;transition:background-color .14s ease}
[data-vibeui-block="contextmenu-006"] tbody tr:hover{background:var(--vibeui-contextmenu-006-hover)}
[data-vibeui-block="contextmenu-006"] tbody tr:focus-visible{outline:2px solid var(--vibeui-contextmenu-006-accent);outline-offset:-2px}
/* Пока меню открыто, видно, к какой строке оно относится. */
[data-vibeui-block="contextmenu-006"] tbody tr[aria-selected="true"]{
background:color-mix(in oklab,var(--vibeui-contextmenu-006-accent) 10%,transparent);
}
[data-vibeui-block="contextmenu-006"] [data-part="tag"]{
display:inline-block;padding:0.0625rem 0.4375rem;border-radius:9999px;
background:var(--vibeui-contextmenu-006-hover);
border:1px solid var(--vibeui-contextmenu-006-border);
font-size:0.6875rem;color:var(--vibeui-contextmenu-006-muted);
}
[data-vibeui-block="contextmenu-006"] [data-part="sum"]{text-align:right;font-variant-numeric:tabular-nums}
[data-vibeui-block="contextmenu-006"] [data-part="menu"]{
position:fixed;margin:0;padding:0.3125rem;
top:var(--vibeui-contextmenu-006-y);left:var(--vibeui-contextmenu-006-x);
min-width:13rem;box-sizing:border-box;
background:var(--vibeui-contextmenu-006-bg);color:var(--vibeui-contextmenu-006-fg);
border:1px solid var(--vibeui-contextmenu-006-border);border-radius:0.75rem;
box-shadow:0 18px 40px -20px oklch(0.2 0.03 265 / 50%);
font-family:var(--vibeui-contextmenu-006-font);
}
[data-vibeui-block="contextmenu-006"] [data-part="head"]{
padding:0.375rem 0.5rem 0.3125rem;margin-bottom:0.25rem;
border-bottom:1px solid var(--vibeui-contextmenu-006-border);
font-size:0.6875rem;font-weight:650;color:var(--vibeui-contextmenu-006-muted);
overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
}
[data-vibeui-block="contextmenu-006"] [data-part="item"]{
display:flex;align-items:center;justify-content:space-between;gap:1.25rem;
width:100%;box-sizing:border-box;
appearance:none;border:0;background:none;cursor:pointer;
padding:0.4375rem 0.5rem;border-radius:0.5rem;
font:inherit;font-size:0.8125rem;color:inherit;text-align:left;
transition:background-color .14s ease;
}
[data-vibeui-block="contextmenu-006"] [data-part="item"]:hover{background:var(--vibeui-contextmenu-006-hover)}
[data-vibeui-block="contextmenu-006"] [data-part="item"]:focus-visible{outline:2px solid var(--vibeui-contextmenu-006-accent);outline-offset:-2px}
[data-vibeui-block="contextmenu-006"] [data-part="item"][data-danger="true"]{color:var(--vibeui-contextmenu-006-danger)}
[data-vibeui-block="contextmenu-006"] [data-part="keys"]{font-size:0.6875rem;color:var(--vibeui-contextmenu-006-muted)}
[data-vibeui-block="contextmenu-006"] [data-part="rule"]{
height:1px;margin:0.3125rem 0.25rem;background:var(--vibeui-contextmenu-006-border);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="contextmenu-006"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_ROWS: Contextmenu006Row[] = [
  { name: "ООО «Полдень»", status: "Оплачен", sum: "84 000 ₽" },
  { name: "Ирина Ковалёва", status: "Ждёт оплаты", sum: "12 500 ₽" },
  { name: "Студия «Круг»", status: "Черновик", sum: "31 200 ₽" },
]

const ACTIONS = [
  { label: "Открыть карточку", keys: "↵" },
  { label: "Скопировать ссылку", keys: "⌘L" },
  { label: "Дублировать строку", keys: "⌘D" },
]

/**
 * Контекстное меню строки таблицы: подсветка цели и вызов с клавиатуры.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Contextmenu006({
  caption = "Счета за март",
  rows = DEFAULT_ROWS,
  accent,
  className,
  style,
  ...props
}: Contextmenu006Props) {
  const menu = useRef<HTMLDivElement>(null)
  const [target, setTarget] = useState<string | null>(null)
  const [spot, setSpot] = useState<{ x: string; y: string } | null>(null)

  const openAt = (x: number, y: number, name: string) => {
    setTarget(name)
    setSpot({ x: `${Math.round(x)}px`, y: `${Math.round(y)}px` })
    menu.current?.showPopover()
    requestAnimationFrame(() =>
      menu.current?.querySelector<HTMLElement>('[data-part="item"]')?.focus(),
    )
  }

  // Клавиша меню и Shift+F10 приходят тем же событием, но без координат.
  const onContextMenu = (
    event: MouseEvent<HTMLTableRowElement>,
    name: string,
  ) => {
    event.preventDefault()

    if (event.clientX === 0 && event.clientY === 0) {
      const box = event.currentTarget.getBoundingClientRect()
      openAt(box.left + 16, box.bottom, name)
      return
    }

    openAt(event.clientX, event.clientY, name)
  }

  const palette = {
    ...(accent ? { "--vibeui-contextmenu-006-accent": accent } : null),
    ...(spot
      ? {
          "--vibeui-contextmenu-006-x": spot.x,
          "--vibeui-contextmenu-006-y": spot.y,
        }
      : null),
    ...style,
  } as CSSProperties

  return (
    <>
      <style href="vibeui-contextmenu-006" precedence="medium">
        {STYLES}
      </style>
      <section
        {...props}
        data-vibeui-block="contextmenu-006"
        aria-label={caption}
        className={className}
        style={palette}
      >
        <table>
          <caption>{caption} · правый клик по строке или Shift+F10</caption>
          <thead>
            <tr>
              <th scope="col">Клиент</th>
              <th scope="col">Статус</th>
              <th scope="col">Сумма</th>
            </tr>
          </thead>
          <tbody>
            {rows.map((row) => (
              <tr
                key={row.name}
                tabIndex={0}
                aria-selected={target === row.name}
                onContextMenu={(event) => onContextMenu(event, row.name)}
              >
                <td>{row.name}</td>
                <td>
                  <span data-part="tag">{row.status}</span>
                </td>
                <td data-part="sum">{row.sum}</td>
              </tr>
            ))}
          </tbody>
        </table>
        <div
          ref={menu}
          data-part="menu"
          popover="auto"
          role="menu"
          aria-label={target ? `Строка: ${target}` : "Строка"}
          onToggle={() => {
            if (!menu.current?.matches(":popover-open")) {
              setTarget(null)
            }
          }}
          onKeyDown={(event) => {
            if (event.key !== "ArrowDown" && event.key !== "ArrowUp") {
              return
            }

            event.preventDefault()
            const items = Array.from(
              menu.current?.querySelectorAll<HTMLElement>(
                '[data-part="item"]',
              ) ?? [],
            )

            if (items.length === 0) {
              return
            }

            const delta = event.key === "ArrowDown" ? 1 : -1
            const from = items.indexOf(document.activeElement as HTMLElement)
            items[(from + delta + items.length) % items.length].focus()
          }}
        >
          <div data-part="head">{target}</div>
          {ACTIONS.map((action) => (
            <button
              key={action.label}
              type="button"
              role="menuitem"
              data-part="item"
              onClick={() => menu.current?.hidePopover()}
            >
              {action.label}
              <span data-part="keys">{action.keys}</span>
            </button>
          ))}
          <div data-part="rule" role="separator" />
          <button
            type="button"
            role="menuitem"
            data-part="item"
            data-danger="true"
            onClick={() => menu.current?.hidePopover()}
          >
            Удалить строку
            <span data-part="keys">⌫</span>
          </button>
        </div>
      </section>
    </>
  )
}