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 triggers
(File, Edit, View, …), each of them opens a dropdown. Menubar is built on top of
Menu, dropdown content is composed from Menu.Item, Menu.Divider and other
Menu components.
How it differs from Menu
Menu is one target that toggles one dropdown. Menubar coordinates multiple menus:
- Only one menu is open at a time. Moving to another target while a menu is open switches the open menu.
- The whole bar is a single tab stop, arrow keys move focus between targets.
If you need a single dropdown attached to one button, use Menu instead.
Composition
Menubar– root elementMenubar.Menu– wraps a single menu, accepts the same props asMenuMenubar.Target– top-level trigger buttonMenubar.Dropdown– dropdown container, accepts the same children asMenu.Dropdown
Trigger and loop
By default, a menu opens when its target is clicked. Once a menu is open, hovering another
target switches to it. Set trigger="hover" to open menus on hover, the menu closes when
the pointer leaves the bar.
Set loop={false} to stop arrow key navigation from wrapping around from the last menu
to the first and vice versa.
Submenus
Use Menu.Sub inside Menubar.Dropdown to create nested submenus, see the
Menu submenus documentation. The usage demo includes
a submenu in the File menu.
Checkbox and radio items
Use Menu.CheckboxItem for toggles and Menu.RadioGroup with Menu.RadioItem for
single-choice options. By default, clicking these items does not close the menu.
Controlled
Use openIndex and onOpenChange props to control which menu is open. openIndex is the
index of the opened Menubar.Menu or null when all menus are closed.
Use defaultOpenIndex to open a menu initially without controlling the state.
Position
By default, dropdowns are positioned at bottom-start. Set the position prop to use a different
Floating UI position for all menus in the bar:
To override settings of a single menu, pass Menu props to Menubar.Menu,
for example position or closeOnItemClick.
Keyboard interactions
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" - Each
Menubar.Targethasrole="menuitem",aria-haspopup="menu"andaria-expanded Menubar.Targetchildren are used as accessible names of the triggers