Menubar
A row of menus across the top of an app or an editor: File, Edit, View. It suits tools with many commands that people learn by place. For a handful of actions use a toolbar or one dropdown menu; for moving between pages, a navigation menu.
Install
npx shadcn@latest add https://thrumui.dev/r/menubar.jsonAdds components/ui/menubar.tsx and installs @base-ui/react@1.9.0. Nothing else in your project changes.
import { Menubar } from "@/components/ui/menubar";Props
| Prop | Type | Default | Description |
|---|---|---|---|
Menubar: orientation | "horizontal" | "vertical" | Default "horizontal" | The direction of the bar, and which arrow keys move along it. In a vertical bar, open the menus to the side with side="inline-end". |
Menubar: loopFocus | boolean | Default true | Whether the arrow keys wrap from the last menu to the first. |
Menubar: modal | boolean | Default true | While a menu is open, the page behind does not scroll and cannot be pressed. |
Menubar: disabled | boolean | Default false | Disables every menu of the bar. |
Menubar: sound | boolean | Default true | Play the bar's sounds, if the visitor has sound on. |
Menubar: className | string | – | Extra classes for the bar. It is as wide as its names and wraps onto more lines in a narrow container. |
MenubarMenu: open, defaultOpen, onOpenChange | boolean, boolean, (open: boolean, details) => void | – | The state of one menu, controlled or not. |
MenubarMenu: disabled | boolean | Default false | The menu's name is dimmed and it cannot be opened. The arrow keys still stop on it. |
MenubarTrigger | button props | – | The name of a menu on the bar, 32 pixels tall. |
MenubarContent: side, align, sideOffset, alignOffset | as DropdownMenuContent | Default "bottom", "start", 8, 0 | Where the list opens. It flips when there is no room. |
MenubarItem: onClick | (event) => void | – | Runs when the item is picked. The menu and the bar close. |
MenubarItem: children, destructive, inset, disabled, closeOnClick, label | as DropdownMenuItem | – | The same options as a dropdown menu item, an icon before the text among them. |
MenubarCheckboxItem: checked, defaultChecked, onCheckedChange | boolean, boolean, (checked: boolean) => void | – | A setting that is on or off. Picking it leaves the menu open. A menu's list is removed while it is closed, so hold the state yourself to keep it between openings. |
MenubarRadioGroup: value, defaultValue, onValueChange | string, string, (value: string) => void | – | A set of radio items of which one is selected. |
MenubarRadioItem: value | string | Required | What the group's onValueChange reports. Unique within the group. |
MenubarGroup, MenubarLabel, MenubarSeparator | div props | – | A group of items, its heading, and a line between groups. A label must sit inside a group or a radio group. |
MenubarShortcut | span props | – | Key hint text at the end of a row. The bar does not listen for the keys. |
MenubarSub, MenubarSubTrigger, MenubarSubContent | as the dropdown menu's | – | A submenu: its state, its row in the parent, and its list. |
Motion and sound
Motion
- The first menu fades in and grows from 96% to full size over 150 ms. Moving to a neighbouring menu swaps the lists at once, so the bar can be scanned quickly.
- A menu name changes its fill over 150 ms on hover and while its menu is open.
- Reduced motion: lists appear and leave at once.
Sound
- A soft rising tone when a menu opens from a press or a key, and a falling one when the bar closes without a pick.
- Walking from one open menu to the next is silent, with the pointer or with the arrow keys: one tone marks the bar opening, not every menu on the way.
- A click when an item or a radio item is picked, and a rising or falling pair of clicks when a checkbox item changes.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- It follows the WAI-ARIA menubar pattern: the bar has the menubar role, each name is a menuitem that opens a menu, and rows are menuitem, menuitemcheckbox or menuitemradio.
- Name the bar with an aria-label that says what it belongs to, as in the example.
- The bar is a panel surface and its menus are floating surfaces. Under a glass material both are translucent, and their tints keep the text at 4.5 to 1 over any page.
- In a container narrower than its names the bar wraps onto more lines. A vertical bar stacks the names and stretches them to one width.
| Keys | Action |
|---|---|
| Tab | Move onto the bar, onto one menu name, and out again. The bar is one tab stop. |
| ← / → | Move to the previous or next menu name. With a menu open, open the neighbouring menu instead. |
| ↑ | On a vertical bar: move to the previous menu name. Past the start it wraps. |
| Home / End | On the bar: move to the first or last menu name. |
| Enter / Space / ↓ | Open the menu with the first item highlighted. On a vertical bar ↓ opens the menu too, and ↑ moves along the bar. |
| ↓ / ↑ | In a menu: move the highlight. Past the end it wraps. |
| A to Z | In a menu: move the highlight to the next item that starts with the typed letters. |
| Enter / Space | Pick the highlighted item. A checkbox or radio item changes and the menu stays open. |
| → | On a submenu row: open the submenu. On any other row: open the next menu of the bar. |
| ← | In a submenu: close it. In a menu: open the previous menu of the bar. |
| Esc | Close the open menu. Focus returns to its name on the bar. |
Source
"use client";
import { useContext, type ComponentProps } from "react";
import { Menu as MenuPrimitive } from "@base-ui/react/menu";
import { Menubar as MenubarPrimitive } from "@base-ui/react/menubar";
import { cn } from "@/lib/utils";
import {
DropdownMenu,
DropdownMenuCheckboxItem,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuShortcut,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
MenuSoundContext,
type DropdownMenuContentProps,
type DropdownMenuProps,
} from "@/components/ui/dropdown-menu";
export type MenubarProps = MenubarPrimitive.Props & {
/** Play a soft sound when a menu opens or the bar closes, a click when an item is picked and a pair of clicks when a checkbox item changes, if the visitor has sound on. */
sound?: boolean;
};
/**
* A row of menus across the top of an app or an editor: File, Edit, View. It is one tab stop; the arrow keys move along it,
* and once one menu is open they walk from menu to menu. Name it with an `aria-label`. It is a panel surface, its menus float.
*/
export function Menubar({ sound = true, className, ...props }: MenubarProps) {
return (
<MenuSoundContext.Provider value={sound}>
<MenubarPrimitive
data-slot="menubar"
data-surface="panel"
className={cn(
"inline-flex max-w-full flex-wrap items-center gap-1 rounded-lg border bg-card p-1 text-card-foreground data-[orientation=vertical]:flex-col data-[orientation=vertical]:items-stretch",
className,
)}
{...props}
/>
</MenuSoundContext.Provider>
);
}
/** One menu of the bar: a `MenubarTrigger` and a `MenubarContent`. It takes the sound setting from the bar. */
export function MenubarMenu(props: Omit<DropdownMenuProps, "sound">) {
const sound = useContext(MenuSoundContext);
return <DropdownMenu sound={sound} {...props} />;
}
/** The name of a menu on the bar. A press opens its menu; while one menu is open, pointing at another name opens that one. */
export function MenubarTrigger({ className, ...props }: MenuPrimitive.Trigger.Props) {
return (
<MenuPrimitive.Trigger
data-slot="menubar-trigger"
className={cn(
"inline-flex h-8 cursor-default items-center rounded-md px-2.5 text-sm font-medium whitespace-nowrap outline-none select-none",
"transition-[background-color,color] duration-150 ease-out motion-reduce:transition-none",
"hover:bg-accent hover:text-accent-foreground focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-ring",
"data-disabled:opacity-50 data-popup-open:bg-accent data-popup-open:text-accent-foreground",
className,
)}
{...props}
/>
);
}
/** The list of one menu. It opens under its name, 8 pixels below the bar. It is a floating surface. */
export function MenubarContent({ sideOffset = 8, ...props }: DropdownMenuContentProps) {
return <DropdownMenuContent data-slot="menubar-content" sideOffset={sideOffset} {...props} />;
}
/** One action. Picking it runs `onClick` and closes the menu. `destructive` turns it red, `inset` lines it up with checkbox and radio items. */
export function MenubarItem(props: ComponentProps<typeof DropdownMenuItem>) {
return <DropdownMenuItem data-slot="menubar-item" {...props} />;
}
/** A setting that is on or off. Picking it flips it and leaves the menu open. */
export function MenubarCheckboxItem(props: ComponentProps<typeof DropdownMenuCheckboxItem>) {
return <DropdownMenuCheckboxItem data-slot="menubar-checkbox-item" {...props} />;
}
/** A set of radio items of which one is selected. */
export function MenubarRadioGroup(props: ComponentProps<typeof DropdownMenuRadioGroup>) {
return <DropdownMenuRadioGroup data-slot="menubar-radio-group" {...props} />;
}
/** One choice of a radio group. Picking it selects it and leaves the menu open. */
export function MenubarRadioItem(props: ComponentProps<typeof DropdownMenuRadioItem>) {
return <DropdownMenuRadioItem data-slot="menubar-radio-item" {...props} />;
}
/** Items that belong together. A `MenubarLabel` inside it gives the group its name. */
export function MenubarGroup(props: ComponentProps<typeof DropdownMenuGroup>) {
return <DropdownMenuGroup data-slot="menubar-group" {...props} />;
}
/** The heading of a group. It must sit inside a `MenubarGroup` or a `MenubarRadioGroup`, which it names. */
export function MenubarLabel(props: ComponentProps<typeof DropdownMenuLabel>) {
return <DropdownMenuLabel data-slot="menubar-label" {...props} />;
}
export function MenubarSeparator(props: ComponentProps<typeof DropdownMenuSeparator>) {
return <DropdownMenuSeparator data-slot="menubar-separator" {...props} />;
}
/** Key hint text at the end of a row. The menu does not listen for the keys. */
export function MenubarShortcut(props: ComponentProps<typeof DropdownMenuShortcut>) {
return <DropdownMenuShortcut data-slot="menubar-shortcut" {...props} />;
}
/** A menu inside a menu. `MenubarSubTrigger` is its row in the parent, `MenubarSubContent` its list. */
export function MenubarSub(props: ComponentProps<typeof DropdownMenuSub>) {
return <DropdownMenuSub {...props} />;
}
export function MenubarSubTrigger(props: ComponentProps<typeof DropdownMenuSubTrigger>) {
return <DropdownMenuSubTrigger data-slot="menubar-sub-trigger" {...props} />;
}
export function MenubarSubContent(props: ComponentProps<typeof DropdownMenuSubContent>) {
return <DropdownMenuSubContent data-slot="menubar-sub-content" {...props} />;
}Files and dependencies
- Adds
components/ui/menubar.tsx- Packages
@base-ui/react@1.9.0- Brings along
- Sound engineDropdown menu
Changelog
- 1.0.0 · 2026-12-03First release.