Skip to Content
BBRICKSv0.7.4
ShellHeader and menus

UserMenu

The signed-in user in the topbar: avatar (and name), a panel with who they are, the app's items and sign out.

import { UserMenu } 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 UserMenu. Written in docs/content/components/UserMenu.md; the props above are read from the code, which wins where the two disagree.

The signed-in user in the top bar: an avatar pill (optionally with the name) that opens a panel with who they are, the app's items and sign out; use it as AppHeader's userMenu, the last tool.

It is a TopbarMenu in its pill variant. The pill's accessible name is the person's name followed by ", account" (label-in-name). The PR Portal shows the user in the sidebar instead (SidebarUser).

Anatomy

  1. Pill (.kit-shell-pill-btn): 44px, white, the avatar at 34px, then the name (showName, max 140px with ellipsis) or the name as screen-reader text.
  2. Panel: .kit-shell-pop-who header (bold name, muted detail, a rule), the items, then the logout footer after a rule.

Variants

PropLookUse when
showName={false} (default)Avatar onlyMost widths.
showNameAvatar and nameWide headers.

States

Closed / open (see TopbarMenu): open puts focus on the first item; Escape returns to the pill.

Usage

<AppHeader
  title="Home"
  search={search}
  onToggleLanguage={toggle}
  actions={<NotificationsMenu items={notifications} onOpenItem={openNotification} onSeeAll={seeAllNotifications} />}
  userMenu={
    <UserMenu
      name="Nour Hassan"
      detail="HushUp"
      avatar={<Avatar name="Nour Hassan" seed={3} size="sm" />}
      items={[{ id: 'profile', label: 'Your profile', href: '/profile' }]}
      logout={<LogoutButton url="/logout" csrfToken={csrf}>Sign out</LogoutButton>}
    />
  }
/>

Where it appears

  • Brand › top bar, last tool (the library's shell; the v3 brand mock's top bar ends at the bell). AppHeader story Default.

Guidelines

Do

  • Put sign out in logout, not in items.
  • Use detail for the brand or team the user acts for.

Don't

  • Don't show both UserMenu and SidebarUser for the same person.

RTL and Arabic

  • The panel opens to the left edge in Arabic; ", account" becomes "، الحساب".

Tokens

TopbarMenu tokens; .kit-shell-pill-btn .kit-av is 34px.

Accessibility

  • The pill is a <button> named "Nour Hassan, account" (name first, label-in-name); the panel is a region with the same name.
  • Keyboard behaviour from TopbarMenu.

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

Source

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

On this page