Skip to content

Menubar

hc-menubar is the desktop application menu bar pattern: a horizontal row of menu buttons (File / Edit / View …), each opening an hc-menu dropdown. It is a thin layer over the existing menu machinery — installMenu() owns the dropdown internals (ARIA, in-menu keyboard, submenus); installMenubar() adds the bar navigation.

import { installMenu, installMenubar } from '@hypermedia-components/core';
installMenu(); // dropdown internals
installMenubar(); // the bar navigation

installMenubar() is idempotent and returns an uninstaller (so is installMenu()). The zero-config @hypermedia-components/core/behaviors entry auto-installs both and picks up content swapped in by htmx.

Each top button is a role="menuitem" that targets its dropdown with popovertarget; the dropdowns are ordinary hc-menu popovers (so they get submenus, checkbox/radio items, and the hc:menuselect event for free).

KeyAction
/ Move between top items (mirrored in RTL). Wraps at the ends.
Home / EndFirst / last top item.
/ Enter / SpaceOpen the focused menu (↓ focuses the first item).
Open the focused menu at its last item.
/ (menu open)Switch to the adjacent menu and open it.
EscClose the menu, returning focus to its top item.

A submenu parent still opens its submenu on (the menubar defers to the submenu machinery), so nested menus keep working.

PrimitiveRequired version
HTML popoverChrome 114, Edge 114, Firefox 125, Safari 17
CSS Anchor PositioningChrome 125, Edge 125, Firefox 147, Safari 26

The dropdowns are ordinary hc-menu popovers, so when Anchor Positioning is missing installMenu() falls back to getBoundingClientRect positioning — the menus still open, dismiss, and behave correctly everywhere popover is supported.

  • The bar is role="menubar" with an aria-label; each top button is a role="menuitem" and gets aria-haspopup="menu" / aria-expanded wired by installMenu().
  • The bar is a single Tab stop (roving tabindex); arrow keys move within it, matching the WAI-ARIA APG menubar pattern.
  • Label each dropdown (aria-labelledby pointing at its button, or aria-label) so the open menu has an accessible name.
Token pathPurpose
menubar.gapGap between top items.
menubar.padding-x / -yBar padding.
menubar.bgBar background.
menubar.borderBar border.
menubar.radiusBar corner radius.
menubar.item-padding-x / -yTop item padding.
menubar.item-radiusTop item radius.
menubar.item-fgTop item text color.
menubar.item-hover-bgTop item hover / open background.
Show the generated CSS variables
--hc-menubar-gap | -padding-x | -padding-y | -bg | -border | -radius
--hc-menubar-item-padding-x | -item-padding-y | -item-radius | -item-fg | -item-hover-bg
  • Menu — the dropdown each top item opens (and the submenu pattern).
  • Toolbar — a roving-tabindex row of controls (not menus).