Skip to content
EspañolEnglish
All components (283)

Top bar

Navigation · TopBar

What it is and when to use it

The application header: the brand on the left, the main navigation horizontally and the actions (notices, account) on the right. With skipTo it comes with the "Skip to content" link already in place.

When to use it

  • At the top of all the screens of a website or an application with few main sections: brand, links (with current on the current page) and actions.
  • skipTo with the id of the main content: whenever there is navigation before the content, which is almost always. skipText changes the text of the link.
  • sticky if the page is long and the actions need to stay at hand while scrolling.

When not to

  • For the menu of a management panel with many sections: SideNav.
  • For the header of a specific screen, with its title and its buttons: PageHeader.
  • For a notice that takes up the full width (maintenance, expired trial): GlobalAlert.

Keyboard: with skipTo, the first Tab shows "Skip to content"; Enter moves focus to the main content, not just the scroll. After that, Tab moves through the brand (if it is a link), the links and the actions.

Accessibility: it is a header (banner) with a nav inside, named "Main" or whatever navigationLabel says. The current page carries aria-current="page" and is marked with background and underline, not just color. The skip link lives out of view until it receives focus: it is not hidden with display: none, which would take it out of the Tab order.

Fine-tuning: CSS variables --amset-bar-sup-*: -background, -font, -gap, -padding-block, -padding-inline. The size moves the gap, the padding and the font size.

What it looks like

<TopBar
  brand="AMSET UI"
  links={[
    { key: 'componentes', label: 'Components', href: '/componentes/', current: true },
    { key: 'empezar', label: 'Start', href: '/empezar/' },
  ]}
  actions={<ButtonLink href="https://storybook.amsetui.com" size="sm" variant="outline">Test bench</ButtonLink>}
  skipTo="contenido"
/>

Props

Import it with import { TopBar } from '@amset/ui'. Required props are marked.

PropTypeWhat it does
brandrequiredReactNodeThe logo or the name. If it is a link, it should lead to the home page.
actionsReactNodeWhat goes on the right: search, notices, account menu.
classNamestringMerged with the library classes; it does not replace them.
linksreadonly BarLink[]—
menuBreakpointstringThe window width below which the links move to the drawer with `navigation="auto"`, as a CSS length (`'64rem'`, `'1024px'`). By default, 40 rem. With another value it is measured with `matchMedia` on mount: until then the 40 rem one applies.
menuContentReactNodeWhat goes in the drawer below the links: the actions that do not fit in the bar, a whole `SideNav`, the user and sign out. With this and no `links` the menu button is shown all the same.
menuLabelstringThe name of the menu button. By default, «Menu».
menuOpenbooleanWhether the drawer is open. If passed, whoever mounts the bar holds the state, with `onMenuOpenChange`.
menuTitlestringThe title of the drawer. By default, the same as the button.
navigationTopBarNavigationWhere the links go. `auto` (default): in the bar, and below `menuBreakpoint` behind a menu button that opens a drawer over the content. `menu`: always behind the button, at any width. `inline`: always in the bar, which wraps onto lines if they do not fit.
navigationLabelstringName of the navigation, in case there is more than one on the page.
onMenuOpenChange(open: boolean) => void—
size"sm" | "md" | "lg"The gap, padding and font size of the bar.
skipTextstring—
skipTostringId of the main content. It adds the skip link, which comes out of its gap when tabbing: without it, whoever uses the keyboard eats the whole navigation on every page before reaching what they came to read.
stickybooleanIt stays attached to the top when scrolling.

It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.

In the test bench

Every state and variant, to try one at a time, on its page at storybook.amsetui.com: