Menubar
A bar of menus, as in a desktop application, where one open menu leads to the next.
A menubar puts several menus side by side, as the File, Edit and View menus of a desktop application. Use it for a tool with many commands, such as an editor; for the actions of one object, a single dropdown menu is enough, and for moving between pages, a navigation menu.
Last action: nothing yet · grid on · comfortable
// apps/docs/examples/ui/menubar.tsx'use client';
import {useState} from 'react';
import { Menubar, MenubarCheckboxItem, MenubarContent, MenubarItem, MenubarMenu, MenubarRadioGroup, MenubarRadioItem, MenubarSeparator, MenubarSub, MenubarSubContent, MenubarSubTrigger, MenubarTrigger,} from '@workspace/active-ui/components/primitives/menubar';
/** * The menus of an editor-like screen in one bar. With one menu open, moving * the pointer or the arrow keys to the next title opens that menu instead. */export default function MenubarExample() { const [last, setLast] = useState('nothing yet'); const [grid, setGrid] = useState(true); const [density, setDensity] = useState('comfortable'); return ( <div className="flex flex-col items-center gap-4"> <Menubar aria-label="Report editor"> <MenubarMenu> <MenubarTrigger>File</MenubarTrigger> <MenubarContent> <MenubarItem onClick={() => setLast('New report')}> New report </MenubarItem> <MenubarItem onClick={() => setLast('Duplicate')}> Duplicate </MenubarItem> <MenubarSub> <MenubarSubTrigger>Export</MenubarSubTrigger> <MenubarSubContent> <MenubarItem onClick={() => setLast('Export as CSV')}> CSV </MenubarItem> <MenubarItem onClick={() => setLast('Export as PDF')}> PDF </MenubarItem> </MenubarSubContent> </MenubarSub> <MenubarSeparator /> <MenubarItem disabled>Print (not available)</MenubarItem> </MenubarContent> </MenubarMenu> <MenubarMenu> <MenubarTrigger>Edit</MenubarTrigger> <MenubarContent> <MenubarItem onClick={() => setLast('Undo')}>Undo</MenubarItem> <MenubarItem onClick={() => setLast('Redo')}>Redo</MenubarItem> </MenubarContent> </MenubarMenu> <MenubarMenu> <MenubarTrigger>View</MenubarTrigger> <MenubarContent> <MenubarCheckboxItem checked={grid} onCheckedChange={setGrid}> Show grid lines </MenubarCheckboxItem> <MenubarSeparator /> <MenubarRadioGroup value={density} onValueChange={setDensity}> <MenubarRadioItem value="comfortable"> Comfortable </MenubarRadioItem> <MenubarRadioItem value="compact">Compact</MenubarRadioItem> </MenubarRadioGroup> </MenubarContent> </MenubarMenu> </Menubar> <p className="text-muted-foreground text-sm" aria-live="polite"> Last action: {last} · grid {grid ? 'on' : 'off'} · {density} </p> </div> );}Usage#
import { Menubar, MenubarContent, MenubarItem, MenubarMenu, MenubarTrigger,} from '@workspace/active-ui/components/primitives/menubar';
<Menubar aria-label="Report editor"> <MenubarMenu> <MenubarTrigger>File</MenubarTrigger> <MenubarContent> <MenubarItem onClick={create}>New report</MenubarItem> </MenubarContent> </MenubarMenu></Menubar>;Anatomy#
Menubar: the bar,role="menubar".Menubar: one menu, with itsMenu Menubar(the title) andTrigger Menubar.Content Inside a menu:
Menubar(Item variant,inset),Menubar,Checkbox Item MenubarwithRadio Group Menubar,Radio Item MenubarwithGroup Menubar,Label Menubarwith its trigger and content,Sub MenubarandSeparator Menubar: as in the dropdown menu.Shortcut
What your application provides#
A name for the bar (
aria-), and the titles and items of its menus.label What each item does. A shortcut only shows a key; binding it is your application's work.
Accessibility and keyboard#
The bar is one tab stop.
←and→move between the titles;↓,EnterorSpaceopens a menu.With a menu open,
←and→move to the neighbouring menu and open it; the pointer does the same when it moves to another title.Inside a menu the keys of the dropdown menu apply;
Escapecloses it and returns the focus to its title.
API#
Menubar#
Import from @workspace/
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
Other parts#
MenubarPortal
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
MenubarMenu
All props come from the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Takes only the props listed.
MenubarTrigger
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
MenubarContent
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
MenubarGroup
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
MenubarSeparator
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
MenubarLabel
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
MenubarItem
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
MenubarCheckboxItem
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
MenubarRadioGroup
All props come from the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
MenubarRadioItem
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
MenubarSub
All props come from the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Takes only the props listed.
MenubarSubTrigger
Props marked Base UI are behaviour of the Base UI part this component is built on.
Props
Events
Called by the component when something happens.
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
MenubarSubContent
All props come from the Base UI part this component is built on.
Props
Other props, such as the standard attributes of the underlying element, className and ref, are passed through.
Parts that take only their element’s attributes
This page adapts the Menubar documentation of shadcn/ui (MIT licence) to this package; see Third-party notices.