组件

Menubar

A desktop-style menu bar: a strip of paper with a pencil ruler along its foot and the menu titles written on it. Hovered, focused or open, a title wears the highlighter; each menu opens the same slip as the dropdown. Roving focus, hover-to-switch and typeahead are Radix's.

安装

terminal
npx shadcn@latest add @wobko/menubar

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Application menu

The shadcn demo on a strip of paper: File with a sub-menu and keycaps, Edit, View with ticked rows, Profiles with a radio group. Hover another title while one is open and the menu follows.

Format menu that acts

Controlled rows change the page under the bar: bold and italic are ticked rows, the paper is a radio group. Every state lives in your component; the menus just report it.

App header (composed)

A real use: the bar sits in an app header beside the title and an account button. Choosing a row reports what happened, and the bar stays one tab stop for keyboard users.

Browser menu (as written)

shadcn's `menubar-demo`, line for line: File, Edit, View and Profiles, with shortcuts, sub-menus, two ticked rows, an inset column and a radio group. Its checkboxes and radio are fixed (`checked`, `value="benoit"` with no handler), so they show the states without changing; the first example lets them change.

API 参考

Menubar

The bar (Radix Menubar root, role=menubar) and the ink host of the strip: a pale paper-shade body under a fine felt outline, a pencil ruler's ticks along the foot. Hairline and without the ruler in calm density.

属性类型默认值说明
value / defaultValue / onValueChangestring / string / (value: string) => void-Which menu is open (a `MenubarMenu` `value`).
dir"ltr" | "rtl"-Reading direction; the arrows and the drawings follow it.
loopbooleantrueArrow keys wrap around the ends of the bar.
seedstring | number-Pins the hand. Default: derived from useId().

MenubarContent

The slip: a Paper that is also the Radix content (role=menu). Rows scroll in a viewport inside it so the shadow is not cut. `max-h-*`, `overflow-*` and `overscroll-*` in `className` are applied to that viewport (shadcn code writes them on the content), the rest stays on the slip. Every Radix Content prop passes through.

属性类型默认值说明
align"start" | "center" | "end""start"Where the slip sits under its title.
alignOffsetnumber-4Nudges the slip so its text lines up with the title.
sideOffsetnumber8Gap between the bar and the slip.
stockStockName"slip"What it is made of: slip, paper, kraft, sticky-* ...
edgeEdgeSpec"cut"Cut (pure CSS), torn, deckle ...
tiltboolean | numbertrueSmall seeded tilt of the sheet; text stays upright.
tape"corner" | "top" | "both" | falsefalseStrips of masking tape holding the slip down.

MenubarLabel

A heading in the typewriter.

属性类型默认值说明
insetbooleanfalseLines the text up with rows that carry a tick or an icon.

MenubarItem

A row; the highlighter is a CSS background.

属性类型默认值说明
insetbooleanfalseLines the text up with rows that carry a tick or an icon.
variant"default" | "destructive""default"Destructive is red, and hatches in red pencil when highlighted.

MenubarCheckboxItem

A pencil box at the start of the row, ticked in blue felt when `checked`.

属性类型默认值说明
checkedboolean | 'indeterminate'-Controlled state.
onCheckedChange(checked: boolean) => void-Called when toggled.

MenubarRadioItem

One choice: a pencil ring with a bold felt dot in the chosen one.

属性类型默认值说明
valuestring-The value this row stands for.

MenubarSubTrigger

The row that opens it, with a hand-drawn chevron; it keeps the highlighter while its sub-menu is open.

属性类型默认值说明
insetbooleanfalseLines the text up with rows that carry a tick or an icon.

无障碍

  • Radix Menubar: role=menubar with menuitem titles (aria-haspopup, aria-expanded). Left and Right (mirrored in RTL) move between titles; Enter, Space or ArrowDown opens a menu with its first row highlighted (ArrowUp on a title opens nothing). Once one is open, hovering another title or pressing Left or Right from a plain row switches menus.
  • Inside a menu: Up and Down move (disabled rows are skipped), Home and End jump, typing a letter jumps to the next row that starts with it, ArrowRight opens a sub-menu and ArrowLeft closes it, Enter or Space chooses, Escape closes and returns focus to the title. The bar is one tab stop.
  • The strip and its ruler are aria-hidden decoration with no pointer events; the titles keep a 28 px hit box. The highlight follows the keyboard as well as the pointer, and keyboard focus on a title also shows the theme's blue focus ring; inside a menu the row with keyboard focus gets a bar of blue felt at its start edge.
  • Ticks, dots, chevrons and pencil boxes are aria-hidden drawings; keycaps are real `kbd` elements. Portalled content repeats the InkProvider's data-density, data-motion and data-theme. In forced-colors mode the strip gives way to a real outline and the hovered, focused or open title takes the system highlight colors.

源码

CLI 会复制进你项目的文件。

正在加载源码