Menubar
A desktop-style bar of menus with one highlight that slides between open menus and instant switching as you sweep across.
- Overlay components
- 16 parts
- 6 examples
@base-ui/react
pnpm dlx shadcn@latest add https://hextaui.com/r/menubar.jsonAdds the component, the HextaUI theme tokens and any HextaUI components it depends on.
Add the theme tokens to your global CSS, if you haven’t yet.
Install the dependencies.
pnpm add @base-ui/react @tabler/icons-react class-variance-authority cnCopy and paste the following code into your project.
components/ui/menubar.tsx components/ui/dropdown-menu.tsx lib/motion.ts Update the import paths to match your project setup.
Each <MenubarMenu /> is a Dropdown menu, so items, checkbox and radio items, submenus, labels and shortcuts work and look exactly the same. Open a menu, then move the pointer or press the arrow keys to sweep across the bar.
Put an icon before a trigger's label, or use an icon on its own with an aria-label. Icon-only triggers get a square shape.
Put an icon before the label. Use variant="destructive" on items that delete or can't be undone.
Disable a single menu with disabled on <MenubarMenu />, or the whole bar on <Menubar />. Arrow keys skip disabled menus.
orientation="vertical" stacks the menus and switches navigation to the up and down arrows. Open the menus to the side with side="inline-end".
Menus, submenus and arrow keys follow the reading direction. Shortcuts stay in keyboard order.
| Key | Action |
|---|---|
| Tab | Moves focus into the menubar, then out of it. |
| ←→ | Moves between menus. With a menu open, opens the next one instead. |
| EnterSpace↓ | Opens the focused menu. |
| ↑↓ | Moves between items in an open menu. |
| → | Opens a submenu from its trigger. |
| Esc | Closes the open menu and returns focus to its trigger. |
- Give the menubar a name with
aria-label. It rendersrole="menubar"and each trigger is a menu item, so screen readers announce it as an application menu. - The bar is a single tab stop. Arrow keys move between menus, so the page's tab order stays short.
- The sliding highlight is decoration. With reduced motion it just appears on the open menu.
Menu parts accept the same props as their Dropdown menu counterparts.
| Prop | Type | Default |
|---|---|---|
orientation | "horizontal" | "vertical" | "horizontal" |
loopFocusWrap from the last menu back to the first. | boolean | true |
modalBlock page scrolling and outside clicks while a menu is open. | boolean | true |
disabled | boolean | false |
render | ReactElement | (props, state) => ReactElement | <div> |
| Attribute | Description |
|---|---|
data-slot="menubar" | Target the bar in CSS. |
data-orientation | The orientation. |
data-has-submenu-open | Present while any menu in the bar is open. |
data-slot="menubar-highlight" | The sliding background behind the open trigger, with data-visible. |
--menubar-radius | Corner radius of the bar. Triggers and the highlight derive theirs from it. |
| Prop | Type | Default |
|---|---|---|
open | boolean | – |
defaultOpen | boolean | false |
onOpenChange | (open: boolean, details) => void | – |
disabled | boolean | false |
| Attribute | Description |
|---|---|
data-slot="menubar-trigger" | Target triggers in CSS. |
data-popup-open | Present while its menu is open. |
data-disabled | Present when disabled. |
| Prop | Type | Default |
|---|---|---|
side | "top" | "bottom" | "left" | "right" | "inline-start" | "inline-end" | "bottom" |
align | "start" | "center" | "end" | "start" |
sideOffset | number | 8 |
alignOffsetLines the menu's items up with the trigger's label. | number | -4 |
| Attribute | Description |
|---|---|
data-slot="menubar-content" | Target menus in CSS. |
data-instant="group" | Present when the menu opened by sweeping from another one. It switches without animating. |
MenubarItem, MenubarCheckboxItem, MenubarRadioGroup, MenubarRadioItem, MenubarGroup, MenubarLabel, MenubarSeparator, MenubarShortcut, MenubarSub, MenubarSubTrigger and MenubarSubContent are the Dropdown menu parts with menubar-* slots. See the Dropdown menu API for their props.
- Dropdown menuA menu of actions and options behind a button, with groups, submenus, checkbox and radio items, and shortcuts.
- MotionThe easing curves, durations and reduced-motion check every component animates with, plus hooks for size morphs and sliding highlights.
- Alert dialogA confirmation dialog for destructive or important actions that waits for async work, and becomes a bottom sheet on phones.
- CommandA searchable list of actions, inline or as a ⌘K palette, with pages, shortcuts and highlighted matches.
- Context menuA menu of actions on right click or long press, with submenus, checkbox and radio items, and hold feedback on touch.
- DialogA window over the page for forms and focused tasks, with a pinned header and footer, nesting, and a swipeable bottom sheet on phones.