Menubar
Desktop application style menubar with a row of menu triggers
Source
LLM docs
Docs
Package
Usage
Menubar is a desktop-application style menu bar: a horizontal row of top-level menu triggers
(File, Edit, View, …) where each trigger opens a dropdown. Arrow keys move between the top-level
menus, and once one menu is opened, moving to a sibling opens it immediately. Menubar follows the
WAI-ARIA menubar pattern.
Menubar is built on top of Menu – each Menubar.Menu is a separate Menu
instance, and the dropdown content is composed from the usual Menu.Item, Menu.Divider,
Menu.Label, Menu.Sub, Menu.CheckboxItem and Menu.RadioItem components.
How it differs from Menu
Menu is a single disclosure widget – one target that toggles one dropdown.
Menubar coordinates multiple menus:
- The root renders
role="menubar"andMenubar.Targetrendersrole="menuitem"triggers witharia-haspopup="menu". - Only one menu in the bar is open at a time. Moving to a sibling while a menu is open switches which menu is open.
- The whole bar is a single tab stop (roving
tabindex) –Tabmoves focus into and out of the menu bar as a single unit, arrow keys move between triggers.
If you need a single dropdown attached to one button, use Menu instead.
Composition
Menubar consists of the following components:
Menubar– root element, owns the open/active state of all menusMenubar.Menu– wraps a single menu, renders aMenuinstance under the hoodMenubar.Target– top-level trigger button (role="menuitem")Menubar.Dropdown– dropdown container, accepts the same children asMenu.Dropdown
Trigger and loop
trigger controls how a menu is opened when none of the menus is currently open:
click(default) – a menu opens when its target is clicked. Once any menu is open, hovering a sibling target switches to it immediately. This matches the behavior of native desktop application menu bars.hover– a menu opens as soon as its target is hovered, even when all menus are closed.
With trigger="hover", a menu opens as soon as its target is hovered and closes when the pointer
leaves the bar:
loop (default true) controls whether arrow key navigation wraps around from the last menu to
the first and vice versa.
Submenus
Use Menu.Sub inside Menubar.Dropdown to create nested submenus. ArrowRight opens a submenu
and moves focus to its first item, ArrowLeft closes it and returns focus to the parent item.
See the Menu submenus documentation for more information.
The usage demo above includes a submenu in the File menu.
Checkbox and radio items
Menubar.Dropdown supports the same selectable items as Menu: Menu.CheckboxItem for toggles
and Menu.RadioGroup with Menu.RadioItem for single-choice options. By default, clicking a
checkbox or radio item does not close the menu.
Controlled
Set openIndex and onOpenChange to control which menu is open. openIndex is the zero-based
index of the opened Menubar.Menu (in DOM order) or null when all menus are closed:
For uncontrolled usage with an initially open menu, use the defaultOpenIndex prop instead.
Position
By default, dropdowns are positioned at bottom-start relative to their target. Change the
position prop to use a different Floating UI position
for all menus in the bar:
Individual menus accept the same props as Menu – pass them to Menubar.Menu to
override settings for a single menu, for example position, withinPortal, closeOnItemClick,
shadow, width or transitionProps.
Keyboard interactions
Menubar implements the keyboard interactions defined by the WAI-ARIA menubar pattern. When RTL
direction is set, ArrowLeft and ArrowRight are swapped.
Styles API
Menubar supports the Styles API; you can add styles to any inner element of the component with the classNames prop. Follow the Styles API documentation to learn more.
Component Styles API
Hover over selectors to highlight corresponding elements
Accessibility
Menubar follows the WAI-ARIA menubar pattern:
- The root element has
role="menubar"andaria-orientation="horizontal". - Each
Menubar.Targethasrole="menuitem",aria-haspopup="menu"andaria-expanded. - The menu bar is a single tab stop – only the active trigger is included in the tab sequence, arrow keys move focus between the triggers.
The labels you pass to Menubar.Target are used as accessible names for the triggers, so make
sure they describe the menu content.