Skip to content
English

How it works

A 56px bar with four slots: start, title, a middle area and actions, then the avatar and its menu. Icon buttons are 36px filled circles and the person is a filled pill, so the bar needs no outlines; one soft hairline sits under it. Width tiers come from the bar's own width through a ResizeObserver, not the viewport, because it usually sits beside a side navigation; under 768px it keeps only the avatar. The title shrinks first, and a breadcrumb node shrinks itself so its collapsed menu can still extend below the bar. The avatar menu is absolutely positioned, not a portal.

Use it for

  • Dashboards and workspaces with a side navigation: the strip at the top right holding the page name or breadcrumb, global actions and the signed-in person.
  • A fixed place for entries unrelated to a page: notifications, help, switch store, sign out.
  • Narrow screens where the side navigation becomes a drawer: put the expand-menu button in start.

Look elsewhere when

  • The page's own title and main button: put them in a page header inside the content area.
  • A marketing site header with a row of links: the top bar does not handle navigation between pages.
  • Inside an ancestor with overflow: hidden that is only as tall as the bar: the avatar menu would be clipped.
  • A mobile app title bar with a back arrow and centered title: that is a different pattern.

Usage

import { TopBar, TopBarAction } from './TopBar.jsx'

const userMenu = [
  { key: 'profile', label: 'Profile settings', icon: <UserIcon /> },
  { key: 'store', label: 'Switch store', icon: <SwapIcon /> },
  { key: 'logout', label: 'Sign out', icon: <ExitIcon />, danger: true },
]

export function AppHeader({ unread, onOpenNotices, onLogout }) {
  return (
    <TopBar
      title="Inventory"
      actions={
        <>
          <TopBarAction label="Notifications" badge={unread} onClick={onOpenNotices}>
            <BellIcon />
          </TopBarAction>
          <TopBarAction label="Help" onClick={() => window.open('/help')}>
            <HelpIcon />
          </TopBarAction>
        </>
      }
      user={{ name: 'Maya Lopez', description: 'Market Street store · Manager', avatarUrl: '/avatars/maya.png' }}
      userMenu={userMenu}
      onUserMenuSelect={(key) => {
        if (key === 'logout') onLogout()
      }}
    />
  )
}

// A breadcrumb as the title; on narrow screens the page shell passes an expand-menu button into start
<TopBar
  start={
    <TopBarAction label="Expand menu" onClick={openNav}>
      <MenuIcon />
    </TopBarAction>
  }
  title={<Breadcrumb items={[{ label: 'Products', href: '/products' }, { label: 'Inventory' }]} />}
  user={{ name: 'Maya Lopez' }}
/>

Props

PropTypeDefaultWhat it does
startReactNode—Leftmost slot, for something like an expand-menu button; 8px from the title.
titleReactNode—Page name or breadcrumb. A string shows at 16px / 600 and truncates; a node (breadcrumb) shrinks and truncates itself.
childrenReactNode—Middle area, such as a global search, filling the width between the title and the actions. On narrow screens the caller hides it.
actionsReactNode—A group of actions on the right, usually a few TopBarAction, 8px apart.
user{ name, avatarUrl?, description? }—The signed-in person: a filled pill with a 32px avatar and the name on the far right; the menu head repeats the avatar with the name and description (store, role). Omit for no avatar area.
userMenu{ key, label, icon?, danger?, disabled? }[]—Menu opened from the avatar; danger items use the danger color and get a separator. Without it the avatar is display only.
onUserMenuSelect(key: string) => void—Called when a menu item is chosen; the menu closes and focus returns to the avatar first.
compactboolean—Show only the avatar, no name. When omitted it follows the bar's own width: under 768px only the avatar.
...restHTMLAttributes<HTMLElement>—Other attributes go to the root <header>. Use --ds-topbar-pad for side padding and --ds-topbar-z for the dropdown layer (default 30).
TopBarAction · labelstring—Required. The button name: used as aria-label and shown as a tip below the button after 400ms of hover or on keyboard focus. Keep it to 1–3 words.
TopBarAction · childrenReactNode—The icon: a 20px SVG using currentColor.
TopBarAction · badgenumber—Number badge: above 99 shows "99+"; 0 or omitted shows nothing. It pops in with a small overshoot when the number changes (not on first paint). The count is added to the accessible name.
TopBarAction · dotbooleanfalseRed dot for new activity without a number; ignored when badge is above 0.
TopBarAction · labelsobject—Replaces built-in text (withCount, withDot), both functions that build the accessible name. Shallow-merged over the English defaults.
TopBarAction · ...restButtonHTMLAttributes<HTMLButtonElement>—Other attributes (onClick, disabled, className…) go to the <button>; ref is supported.

Accessibility

  • The root is a <header>; the avatar button has aria-haspopup="menu", aria-expanded and aria-controls, and the menu uses role="menu", "menuitem" and "separator".
  • On the avatar button Enter, Space and Down open the menu on the first item, Up on the last; inside, Up and Down cycle (skipping disabled), Home and End jump, Enter or Space selects.
  • Esc closes only the menu and returns focus to the avatar; Tab closes and moves on; clicking outside or moving focus out closes it.
  • With only the avatar shown the name is visually hidden, not removed, so the button keeps the person's name; TopBarAction needs a label, and badge counts or "new activity" are appended to it.
  • The text tip shows after 400ms of hover or at once on keyboard focus, and closes on press or Esc; none on touch.
  • Buttons have a focus ring (outline in forced-colors mode); targets are 44px on touch, and reduced motion fades without movement and does not pop badges.

Motion

The avatar menu grows from the avatar in 200ms ease-out (scale 0.96 and 6px) and leaves in 140ms ease-in; the tip (an ink pill with a caret) scales in over 160ms; a changed badge pops from 0.4 with a spring overshoot in about 400ms; hover colours take 160ms and a press scales buttons to 0.94; menu highlights have no transition.

Add it to your project

Copy the prompt into Codex or Claude Code. The agent reads the published source, shows you what it will write and adds the component next to your own.

TopBar.jsxtop-bar.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Navigation