Menubar
Desktop application style menubar with a row of menu triggers
Source
Package
Usage
Menubar is a horizontal row of menu triggers (File, Edit, View), each opening a dropdown.
It 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 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 on click, and hovering another target switches the open menu.
Set trigger="hover" to open menus on hover. Set loop={false} to stop arrow key
navigation from wrapping around:
Submenus
Use Menu.Sub inside Menubar.Dropdown to create nested submenus, see
Menu submenus. The usage demo above has 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. 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:
Controlling with useMenubar
Menubar supports the controller pattern. Use the useMenubar hook
to manage Menubar state. When controller is set, the open index and loop props of
Menubar are ignored, pass them to useMenubar instead:
Opened: null, focused: 0, menus: 0. Press Alt + F to open the File menu from anywhere.
useMenubar returns the current state, actions and queries:
Position
Set the position prop to change the dropdown position
of 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 or focus a selector to highlight its elements
Accessibility
Set aria-label on Menubar to give the bar an accessible name: