Skip to content

React Menubar

A glass desktop-style React menubar with File, Edit and View menus, reached with one Tab stop and walked with the arrow keys.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/menubar.json

Shopping list: oat milk, limes, basil.

  • Menubar
  • MenubarMenu
  • MenubarContent
  • MenubarTrigger
  • +2 more

Notes app

View toggles the sidebar, the word count and the text size; File → Open recent switches notes. Everything else shows a toast.

Product ideas

Glass that behaves: blur the backdrop, never the words. Motion that shows where things came from, then gets out of the way when asked.

24 words

Files to copy

9 folders · 10 files · 4 packages
From theme/src/
  • components/menu/
  • components/menubar/
  • components/drawer/parts/sheet.tsx
  • components/kbd/
  • components/status-icons/
  • hooks/{use-latest.ts, use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, form.ts, glide-highlight.tsx, popup-a11y.ts, popup-motion.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/menubar.jsonRegistry item: menubar. The styles need the Tailwind v4 glass UI setup.
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Edit and Help menus

Shortcut hints, a disabled item and a link item. The hints are display only: wire the handlers yourself.

API

PropTypeDefaultDescription
orientation"horizontal" | "vertical""horizontal"Which arrow keys move between menus.
loopFocusbooleantrueArrow keys wrap from the last menu to the first.
modalbooleantrueLock page scroll and outside clicks while a menu is open.
disabledbooleanfalseDisable the whole bar.
classNamestringNoneClasses for the glass bar. It scrolls sideways if the menus don't fit.
Menubar ...propsBase UI propsNoneThe rest is passed to the underlying Base UI part (for example style, render).
Menu ...propsBase UI propsNoneThe rest is passed to the underlying Base UI part (for example defaultOpen, loopFocus, highlightItemOnHover, modal, onOpenChange, onOpenChangeComplete).
PropTypeDefaultDescription
labelsPartial<MenuLabels>defaultMenuLabelsSpoken text. Merged over defaultMenuLabels. Every other string, for translation: labels={{ submenu: "…" }}; omitted keys keep the English of defaultMenuLabels. All 2 keys of MenuLabels are listed in the key table under the props table.
anchorElement | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null) | nullNoneElement to position against instead of the trigger.
side"top" | "bottom" | "left" | "right" | "inline-start" | "inline-end""bottom"Preferred side of the trigger; it flips when there is no room.
align"center" | "end" | "start""start"Sets the alignment along that side.
sideOffsetnumber8Gap between the trigger and the menu, in px (each part has its own default).
alignOffsetnumber-4Shift along the alignment axis, in px (each part has its own default).
collisionPaddingnumber12Space kept from the viewport edges, in px.
positionerClassNamestringNoneClasses for the positioner (the fixed element around the popup).
MenubarMenuMenu props (open, onOpenChange…)NoneHolds one menu in the bar.
MenubarTrigger disabledbooleanfalseDisables this menu so it cannot be opened.

Keyboard

KeysAction
TabReach the bar once.
Arrow Left/Arrow RightMove between menus; while one is open, switch the open menu.
Arrow Down/Enter/SpaceOpen the focused menu.
Arrow Down/Arrow UpMove between items; the list wraps.
Home/EndJump to the first or last item.
Type a letterJump to the next item that starts with it (typeahead).
Enter/SpaceRun the highlighted item (a checkbox or radio item toggles and keeps the menu open).
EscapeClose the menu and return focus to its trigger.

Accessibility

  • role="menubar" with menu triggers (aria-haspopup, aria-expanded); name it with aria-label.
  • Items are 44 px tall on touch screens, and the bar scrolls sideways instead of wrapping on narrow screens.
  • Shortcut hints are shown as keys and exposed through aria-keyshortcuts.

When to use Menubar

  • Use it as a desktop-style app menu bar for a web-based editor or admin tool with File, Edit and View menus along the top, where many commands are grouped the way a desktop application groups them.
  • Use it when hovering a neighboring trigger should switch the open menu, as in desktop apps, and the accent tint should glide from one trigger to the next.
  • Use it on narrow screens, where the bar scrolls sideways instead of wrapping to a second row, and set orientation="vertical" when you want the triggers stacked in a column.
  • Skip it when you have one menu behind one button; Dropdown menu is simpler, and a site's top-level links with panels of content belong in a navigation menu instead.
  • Pair it with MenuItem, MenuCheckboxItem and MenuSub for the contents, KbdShortcut for shown key combinations, and CommandPalette so rarely used commands are searchable too.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .