Menu

Menubar

A desktop-style menubar: arrows move between sections and the down arrow opens the list.

  • menu
  • menubar
  • keyboard
  • desktop

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/menu-003?lang=en

Стрелки ходят по разделам, стрелка вниз открывает список

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 "menu-003" (Menubar) 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/menu-003.json

Registry item: https://vibeui.ru/r/menu-003.json
Installs to: components/vibeui/menu-003.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 desktop-style menubar: arrows move between sections and the down arrow opens the list.

A menubar: sections with keyboard navigation, hover switching of the open menu and focus return on Escape. Zero dependencies, one file.

## 3. How to use it
import { Menu003 } from "@/components/vibeui/menu-003"

<Menu003 menus={[{ label: "File", items: ["New"] }]} />

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-menu-003-* palette — do not swap it for your theme tokens
- arrow keys between titles: that is what separates a menubar from a row of buttons
- switching the open menu by hovering a neighbouring title
- returning focus to the title after Escape
- role="menubar" with a name and aria-expanded on the titles
- the top layer on the list: a menu must overlap content

## 6. You may change
- the menus array and their items
- the selection handlers
- the accent through the accent prop
- the title height

## 7. Rules
- A menubar is a desktop pattern: phones need something else, usually a bottom sheet.
- Nested submenus are out of scope: they need recursion and their own keyboard model.
- The items do nothing: handlers belong to the caller.
- 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/menu-003.json
https://vibeui.ru/r/menu-003.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-menu-003-*. Клиентский: "use client". Ссылки на заголовки хранятся массивом ref, стрелки переносят фокус между ними, стрелка вниз открывает список, 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,
  KeyboardEvent,
} from "react"

export type Menu003Menu = {
  label: string
  items: string[]
}

export type Menu003Props = Omit<ComponentPropsWithoutRef<"div">, "children"> & {
  menus?: Menu003Menu[]
  accent?: string
}

// Идея компонента: строка меню как в настольной программе. Её отличие от ряда
// кнопок — в клавиатуре: стрелки влево-вправо ходят между заголовками, вниз
// открывает список, Escape закрывает. Открытое меню переключается наведением
// на соседний заголовок, и это тоже ожидаемое поведение, а не украшение.
const STYLES = `
:where([data-vibeui-block="menu-003"]){
--vibeui-menu-003-bg:oklch(1 0 0);
--vibeui-menu-003-fg:oklch(0.24 0.014 265);
--vibeui-menu-003-muted:oklch(0.56 0.014 265);
--vibeui-menu-003-border:oklch(0.9 0.006 265);
--vibeui-menu-003-hover:oklch(0.96 0.004 265);
--vibeui-menu-003-accent:oklch(0.55 0.17 265);
--vibeui-menu-003-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="menu-003"]{
position:relative;display:inline-flex;flex-direction:column;
width:100%;max-width:22rem;box-sizing:border-box;
font-family:var(--vibeui-menu-003-font);color:var(--vibeui-menu-003-fg);
}
[data-vibeui-block="menu-003"] [data-part="bar"]{
display:flex;gap:0.125rem;padding:0.25rem;
border:1px solid var(--vibeui-menu-003-border);border-radius:0.625rem;
background:var(--vibeui-menu-003-bg);
}
[data-vibeui-block="menu-003"] [data-part="title"]{
appearance:none;cursor:pointer;
height:1.875rem;padding:0 0.625rem;border:0;border-radius:0.4375rem;
background:transparent;color:inherit;font:inherit;font-size:0.8125rem;font-weight:600;
}
[data-vibeui-block="menu-003"] [data-part="title"]:hover{background:var(--vibeui-menu-003-hover)}
[data-vibeui-block="menu-003"] [data-part="title"][aria-expanded="true"]{background:var(--vibeui-menu-003-hover)}
[data-vibeui-block="menu-003"] [data-part="title"]:focus-visible{outline:2px solid var(--vibeui-menu-003-accent);outline-offset:-2px}
/* Список висит под строкой и перекрывает содержимое: меню — верхний слой. */
[data-vibeui-block="menu-003"] [data-part="list"]{
position:absolute;top:calc(100% + 0.25rem);z-index:20;
display:flex;flex-direction:column;min-width:11rem;
margin:0;padding:0.3125rem;list-style:none;
border:1px solid var(--vibeui-menu-003-border);border-radius:0.75rem;
background:var(--vibeui-menu-003-bg);
box-shadow:0 18px 40px -22px oklch(0.2 0.02 265 / 55%);
}
[data-vibeui-block="menu-003"] [data-part="item"]{
display:block;width:100%;min-height:1.875rem;padding:0 0.5rem;
appearance:none;border:0;border-radius:0.4375rem;background:transparent;color:inherit;
font:inherit;font-size:0.8125rem;text-align:left;cursor:pointer;
}
[data-vibeui-block="menu-003"] [data-part="item"]:hover{background:var(--vibeui-menu-003-hover)}
[data-vibeui-block="menu-003"] [data-part="item"]:focus-visible{outline:2px solid var(--vibeui-menu-003-accent);outline-offset:-2px}
[data-vibeui-block="menu-003"] [data-part="hint"]{
margin-top:0.5rem;font-size:0.75rem;color:var(--vibeui-menu-003-muted);
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="menu-003"] *{animation:none!important;transition:none!important}}
`

const DEFAULT_MENUS: Menu003Menu[] = [
  { label: "Файл", items: ["Создать", "Открыть", "Сохранить", "Экспорт"] },
  { label: "Правка", items: ["Отменить", "Повторить", "Найти и заменить"] },
  { label: "Вид", items: ["Сетка", "Линейки", "Тёмная тема"] },
  { label: "Помощь", items: ["Документация", "Горячие клавиши"] },
]

/**
 * Строка меню с клавиатурой: стрелки ходят по заголовкам, вниз открывает.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Menu003({
  menus = DEFAULT_MENUS,
  accent,
  className,
  style,
  ...props
}: Menu003Props) {
  const [open, setOpen] = useState<number | null>(null)
  const titles = useRef<(HTMLButtonElement | null)[]>([])

  const palette = {
    ...(accent ? { "--vibeui-menu-003-accent": accent } : null),
    ...style,
  } as CSSProperties

  const onKeyDown = (event: KeyboardEvent<HTMLElement>, index: number) => {
    if (event.key === "ArrowRight" || event.key === "ArrowLeft") {
      event.preventDefault()
      const step = event.key === "ArrowRight" ? 1 : -1
      const next = (index + step + menus.length) % menus.length
      titles.current[next]?.focus()
      if (open !== null) setOpen(next)
    } else if (event.key === "ArrowDown") {
      event.preventDefault()
      setOpen(index)
    } else if (event.key === "Escape") {
      setOpen(null)
      titles.current[index]?.focus()
    }
  }

  return (
    <>
      <style href="vibeui-menu-003" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="menu-003"
        className={className}
        style={palette}
      >
        <div data-part="bar" role="menubar" aria-label="Главное меню">
          {menus.map((menu, index) => (
            <button
              key={menu.label}
              ref={(node) => {
                titles.current[index] = node
              }}
              type="button"
              role="menuitem"
              data-part="title"
              aria-haspopup="true"
              aria-expanded={open === index}
              onClick={() => setOpen(open === index ? null : index)}
              onMouseEnter={() => {
                // Открытое меню переключается наведением: так работают все
                // настольные строки меню.
                if (open !== null) setOpen(index)
              }}
              onKeyDown={(event) => onKeyDown(event, index)}
            >
              {menu.label}
            </button>
          ))}
        </div>
        {open !== null ? (
          <ul
            data-part="list"
            role="menu"
            aria-label={menus[open].label}
            onKeyDown={(event) => {
              if (event.key === "Escape") {
                setOpen(null)
                titles.current[open]?.focus()
              }
            }}
          >
            {menus[open].items.map((item) => (
              <li key={item}>
                <button
                  type="button"
                  role="menuitem"
                  data-part="item"
                  onClick={() => setOpen(null)}
                >
                  {item}
                </button>
              </li>
            ))}
          </ul>
        ) : null}
        <p data-part="hint">
          Стрелки ходят по разделам, стрелка вниз открывает список
        </p>
      </div>
    </>
  )
}