Skip to Content
BBRICKSv0.7.4
ShellHeader and menus

TopbarMenu

A topbar circle (mock .circle) or pill that opens a panel under it: the console's Help menu, the PR portal's "New" menu, the user menu. A disclosure, not an ARIA menu: opening it (click, Enter, Space or ArrowDown) puts focus on its first item; Tab moves through the panel, ArrowDown/ArrowUp too (wrapping, and from the trigger into the panel while it is open); Escape closes it and returns focus to the trigger; a click outside, or focus leaving the menu, closes it.

import { TopbarMenu } from '@ergasti/bricks';

Examples

Menus

A button that opens a menu: Arrow keys move, Enter picks, Escape closes and returns focus. Items run onSelect, or link with href; keepOpen leaves the menu open (copy link).

Code
import { Icon, TopbarMenu, UserMenu, Avatar } from '@ergasti/bricks';

function Menus() {
  return (
    <div style={{ display: 'flex', gap: 12, justifyContent: 'flex-end', flexWrap: 'wrap' }}>
      <TopbarMenu label="Help" trigger={<Icon name="help" />} items={[{ id: 'copy', label: 'Copy link to this view', keepOpen: true }, { id: 'contact', label: 'Contact TRNDR', href: 'https://example.com', external: true }]} />
      <TopbarMenu label="New" variant="pill" trigger={<><Icon name="motivation" /> New</>} items={[{ id: 'ch', label: 'Challenge', sub: 'Target or leaderboard', icon: 'motivation' }, { id: 'ap', label: 'Affiliate program', sub: 'For a brand without one', icon: 'coupons' }]} />
      <UserMenu name="Nour Hassan" detail="HushUp" avatar={<Avatar name="Nour Hassan" seed={3} size="sm" />} logout={<button type="button">Sign out</button>} />
    </div>
  );
}

Props

Prop

Type

Design guidance

How the BRICKS design system uses TopbarMenu. Written in docs/content/components/TopbarMenu.md; the props above are read from the code, which wins where the two disagree.

A top-bar button that opens a small panel of items under it: a 44px circle (Help) or a pill (the PR Portal's raspberry "+ New"); use it in AppHeader's actions for help, create and account menus.

It covers the mocks' .circle help button and the PR mock's "+ New" menu (.newwrap: Challenge "Target or leaderboard", Affiliate program "For a brand without one"); UserMenu is built on it. It is a disclosure, not an ARIA menu: opening it puts focus on the first item, Tab and the arrows move through the panel, Escape closes it and returns focus to the trigger, and a click outside or focus leaving closes it.

Anatomy

  1. Trigger: .kit-shell-circle (44px round, icon) or .kit-shell-pill-btn (44px pill; tone="rasp" filled raspberry); optional raspberry dot (.kit-shell-dotr).
  2. Panel (.kit-shell-pop, role="region" named by label): 300px, radius 18, under the trigger, end-aligned.
  3. Header (optional): free content (the user's name and role).
  4. Items (.kit-shell-pop-item--row): optional 34px raspberry-50 icon tile, a 600 label, a muted sub; <a> with href (new tab with external) or <button>.
  5. Footer (.kit-shell-pop-foot, after a rule): sign out.

Variants

PropValueLookUse when
variant'circle' (default)44px round icon buttonHelp, settings.
variant'pill'Pill with icon/avatar and words"New", the user.
tone'default'White pillUser menu.
tone'rasp'Filled raspberry pillThe PR "+ New" (B21).
dottrueRaspberry dot on the circleSomething new or unread.

States

StateHow
Closedaria-expanded="false".
Openclick, Enter or Space (focus on the first item), ArrowDown (first item) or ArrowUp (opens; with the menu open, ArrowDown / ArrowUp move to its first / last item); onOpen called.
Item kept openkeepOpen (an inline status follows, "Link copied").
Hover / focusTrigger border darkens / raspberry focus ring; items --soft hover, inset focus ring.

Types

TopbarMenuItem (items): { id, label, sub?, icon?, href?, external?, onSelect?, keepOpen? }.

Usage

// Brand dashboard help
<TopbarMenu
  label="Help"
  trigger={<Icon name="help" />}
  items={[
    { id: 'copy', label: 'Copy link to this view', onSelect: copyLink, keepOpen: true },
    { id: 'contact', label: 'Contact TRNDR', href: 'https://wa.me/…', external: true },
  ]}
/>
// PR Portal "+ New", after the bell
<AppHeader
  title="Challenges"
  search={search}
  actions={<>
    <NotificationsMenu items={notifications} onOpenItem={openNotification} onSeeAll={seeAllNotifications} />
    <TopbarMenu label="New" variant="pill" tone="rasp" trigger={<><Icon name="plus" /> New</>}
      items={[
        { id: 'ch', label: 'Challenge', sub: 'Target or leaderboard', icon: 'motivation', onSelect: newChallenge },
        { id: 'ap', label: 'Affiliate program', sub: 'For a brand without one', icon: 'coupons', onSelect: newProgram },
      ]} />
  </>}
/>

Where it appears

  • Brand › every screen › top bar › Help circle. Screens: Brand*.
  • PR Portal › every screen › top bar › "+ New" (Challenge / Affiliate program; only Gift on the gifts pages). Screen: Pr*, PR · Home (open).
  • Inside UserMenu.

Guidelines

Do

  • Keep 2–5 items; add a sub when the label alone is ambiguous.
  • Use keepOpen only when the item shows its result inside the panel.

Don't

RTL and Arabic

  • The panel aligns to the trigger's end edge (left in Arabic); icon tiles sit on the right.

Tokens

--card, --line, --ink, --ink-3, --soft, --rasp, --rasp-d, --rasp-50 (icon tile), --focus-ring, --focus-ring-inset, --color-control-border-hover.

Accessibility

  • Disclosure: the trigger is a <button> with aria-expanded / aria-controls; circle triggers are named by aria-label, pill triggers by their words.
  • The panel is a labelled region; items are real links and buttons, so Tab works; ArrowUp/Down wrap; Escape returns focus to the trigger; leaving focus closes it.
  • External links open with rel="noopener noreferrer".

Found in the source

  • Roles in the markup: region.
  • ARIA attributes set: aria-label, aria-expanded, aria-controls, aria-hidden.
  • Keys the code handles: ArrowDown.
  • It moves focus in code.
  • Its tests cover: “keyboard: ArrowDown on the trigger opens it on the first item, arrows move (wrapping), Escape closes and returns focus”; “B8: opening by Enter or click puts focus on the first item; the arrows reach the panel from the trigger while open”; “B8: Tab past the last item (focus leaving the menu) closes it, and focus goes on”.

Read from the component's source and tests. See Accessibility for the patterns the library follows.

See also: useLanguage · Icon · Avatar · AppHeader · HeaderSearch · LanguageToggle · LogoutButton

Source

src/shell/TopbarMenu.tsx (line 52) on GitHub.

On this page