Skip to
Keyboard shortcuts

Use the up and down arrow keys to move between items. Press Alt+Shift+K to open this list again.

Alpha version out now. The API may still change.

TopBar

A slim bar above the site header with a line of text at the start and a navigation of tools at the end, such as the language or contact.

Package
@kvirn-ui/react
Testing
Automated. Core 0 of 2, Release 0 of 3

When to use it#

  • Use it first in the site header for a line a visitor may need on every page: who runs the service, the latest news, and a few tools such as language, easy-to-read or contact.
  • Write the text first and the navigation last. Reading order and focus order follow the DOM, so they are the visual order.
  • Give the navigation inside it a label that differs from the main navigation, since the bar itself is not a landmark.
  • Not for the main menu: use Navigation. Not for a message that must be noticed: use Alert.

Example#

Use cases#

A tool that does something on the page

Some tools act on the page and don’t go to another one: print, say. Put a Button in the bar and give it the class kv-button--link. It looks like a link and a screen reader reads it as a button. Tab reaches it in the order you wrote.

The contact centre is open on weekdays, 8 to 16.

Warning: Don't forget

Use a link to go to a page and a button to do something. A button answers Space as well as Enter, a link only Enter (4.1.2 Name, Role, Value, A).

A bar doesn’t need a navigation. For a single link, such as the phone number of the contact centre, write the link directly in the bar after the text. The theme treats a link that stands on its own as a bar item: at least 24 pixels tall (2.5.8 Target Size (Minimum), AA), and underlined only when you point at it.

The contact centre is open on weekdays, 8 to 16.

Call 0123-456 78

A bar with a fill

Set variant to primary, secondary or accent to fill the bar across the full width. Its text, links, focus ring and the current tool take the fill’s on-colour, the colour made to be read on that fill. The theme’s contrast check covers each fill: 4.5:1 for text, and 7:1 in the two high-contrast themes. A link in a sentence stays underlined.

Props in this example:

Warning: Don't forget

Write a sentence in a <p>, never a bare <div>: a link directly in a div of the bar counts as a bar item and loses its underline at rest, so it is no longer clear that it is a link (1.4.1 Use of Color, A).

Your own element

When you render the bar element yourself, for example inside a component of your own, call useTopBar and spread topBarProps on it. You get only the class: no role, ARIA or tabindex. To add a class of your own, join it with mergeProps.

A service from the municipality of Norrvik.

Props in this example:

Accessibility#

What it does for you#

  • APG pattern: none: a plain <div> around your text and a Navigation.
  • Deviations: none
  • Native elements used: <div>; inside it the elements you write (a <p>, a <nav>, <a href>).
PartElement / roleARIA / stateNotes
TopBar<div>, no rolenoneNo landmark of its own: a Navigation inside is the landmark, named by its label.
TopBar variantclass onlynoneprimary, secondary or accent adds kv-top-bar--<variant>; none adds no class.
childrenyoursyoursLaid out at the start and the end in DOM order, so reading and focus order are the visual order (1.3.2 Meaningful Sequence, A; 2.4.3 Focus Order, A).

The navigation's own rows (aria-current on one link) are the Navigation's. useTopBar({ variant }) gives the same frozen topBarProps (only className) for your own element.

It announces nothing.

What you need to do#

  • Text first, the navigation last, each a child of the bar.
  • Name the navigation with its label, and mark the current link.
  • A link in the text says where it goes (2.4.4 Link Purpose (In Context), A).
  • If you make the bar sticky, check that the focused control is not hidden behind it (2.4.11 Focus Not Obscured (Minimum), AA).
  • Write a sentence in a <p>, never a bare <div>: a link directly in a div of the bar is a bar item and loses its resting underline.

Warning: Don't forget

Name the navigation inside the bar, and give it a different name from the main menu. A screen reader user picks a landmark by its name. A development warning fires if a name is missing or used twice (2.4.6 Headings and Labels, AA).

Visual and modes#

  • No fill by default: the page's colours. primary, secondary and accent fill the bar, and its text, text links (a link in a sentence stays underlined at rest), focus ring and current navigation bar take the colour made for that fill. Text meets 4.5:1 on every fill, and 7:1 in the contrast themes, checked automatically in every theme. The focus ring has about the same colour as the fill itself, so it uses the on-fill colour instead. The primary site header is a darker band with the same on-fill colours.
  • A bar without a fill marks its current tool with bolder text and a straight bar at the item's block end, never the Navigation's solid fill. In forced colours the item takes the system link colour and the theme's own bar marks it.
  • No type rules of its own: the text takes its size from what it sits on. Bar items (a link that is a direct child of the bar or of a side, a Navigation item, a link-look button) are at least 24 by 24 CSS px at every width (2.5.8 Target Size (Minimum), AA), in the bar's on-colour, underlined on hover only, with no hover background. A link in a sentence is not a bar item: it keeps its underline at rest (1.4.1 Use of Color, A). A popup opened from the bar keeps its own look.
  • 320px: the two sides wrap onto their own rows, nothing is hidden (1.4.10 Reflow, AA). The text-spacing sweep applies the 1.4.12 spacing and fails on a box that clips its content.
  • forced-colors behaviour: links take the system link colour. A variant's fill drops to the system background with a thin edge in the system text colour, the focus ring takes the highlight colour, and the theme's link-colour bar marks the current item; so does the primary site header's band.
  • reduced-motion behaviour: nothing animates.
  • RTL: logical properties; the text is at the right and the navigation at the left.

Focus management#

  • Initial focus: not moved.
  • Trap: no.
  • Restore to: not needed.
  • Never obscured by: nothing, as the bar is not sticky.

WCAG success criteria#

  • 1.3.1 Info and Relationships (A)
  • 1.3.2 Meaningful Sequence (A)
  • 1.4.1 Use of Color (A)
  • 1.4.3 Contrast (Minimum) (AA)
  • 1.4.10 Reflow (AA)
  • 1.4.11 Non-text Contrast (AA)
  • 1.4.12 Text Spacing (AA)
  • 2.4.3 Focus Order (A)
  • 2.4.4 Link Purpose (In Context) (A)
  • 2.4.7 Focus Visible (AA)
  • 2.5.8 Target Size (Minimum) (AA)
  • 4.1.2 Name, Role, Value (A)

Keyboard#

Focus
native
Selection follows focus
n/a
Arrows wrap
n/a
Shortcuts
none
KeyWhereWhat happens
Tabin the barMoves through its bar items in DOM order
Test: top-bar.test.tsx › Tab moves through the bar items in DOM order
Shift+Tabin the barMoves back through its bar items
Test: top-bar.test.tsx › Shift+Tab moves back through the bar items
Entera linkFollows it
Test: top-bar.test.tsx › Enter follows a link
Entera link-look buttonActivates it
Test: top-bar.test.tsx › Enter or Space activates a link-look button
Spacea link-look buttonActivates it
Test: top-bar.test.tsx › Enter or Space activates a link-look button

The bar handles no key itself: arrows, Home and End do nothing (top-bar.test.tsx › the bar handles no key itself: arrows, Home and End move nothing). The links and buttons keep their native keys (Link, Button).

Read aloud#

State or actionExpected phrase(s) as read aloudLive region politenessTest
The barits children in DOM order, no banner, region or group phrase of its ownnonetop-bar.test.tsx › the bar reads in DOM order with no phrase of its own, the navigation by its label, the current tool as the current item, a link-look button as a button
The navigationnavigation, Verktyg (the label "Tools", in Swedish)nonethe same test
The current toollink, Documentation, current itemnonethe same test
A link-look buttonbutton, Display settingsnonethe same test

API reference#

import { TopBar, useTopBar } from '@kvirn-ui/react'

TopBar

Renders <div> with no role: it is not a landmark, a Navigation inside it is. It takes every attribute of a <div> and passes ref to it. Its children are yours, laid out at the start and the end in DOM order. The default theme is described on Theming.

PropTypeDefaultDescription
variant'primary' | 'secondary' | 'accent'noneThe fill. None adds no class and no fill: the page’s colours. primary, secondary or accent adds kv-top-bar--<variant>: a full-width fill with its on-colour text, links, focus ring and current navigation bar.
Class or attributeValuesMeaning
kv-top-baralwaysThe part class. The default theme lays out the two sides and wraps them onto their own rows when there is no room, as at 320 pixels wide.
kv-top-bar--primaryvariant="primary"The primary fill with its on-colour. The default adds no class.
kv-top-bar--secondaryvariant="secondary"The secondary fill with its on-colour.
kv-top-bar--accentvariant="accent"The accent fill with its on-colour.

useTopBar

Options

PropTypeDefaultDescription
variant'primary' | 'secondary' | 'accent'noneThe fill. Adds kv-top-bar--<variant> to topBarProps.className.

Result

PropTypeDefaultDescription
topBarPropsTopBarPartProps–Spread on your element: only the class. It adds no role, ARIA or tabindex, and the same frozen object comes back every time.

Testing#

The automated tests prove the keyboard behaviour, the names and states, that axe finds no violations in every story and theme, and, for the components they cover, that the stories hold up in forced colours, reduced motion, text spacing and a 320 pixel width. An Automated row passes on these tests alone. A Core or Release row passes only when an automated agent check and a person on the real assistive technology have both checked it. "agent-verified" means automated tests in the repository (with a virtual screen reader for the screen reader rows), not the real assistive technology.

AT + browser + OSAgent checkHuman checkResultNotes
Automated (re-runnable tests)
axe, WCAG 2.2 A and AA, every story, 4 themespassn/apasstop-bar.stories.tsx, every story, 4 themes
Markup and ARIA (roles, names, ids, states)passn/apasstop-bar.test.tsx › the root is a plain div with no role, and the Navigation inside it is the landmark; expectNoA11yViolations
Keyboard contract rows (Vitest browser)passn/apass5 rows, each names a test (top-bar.test.tsx › Tab moves through the bar items in DOM order)
Focus order and managementpassn/apasstop-bar.test.tsx asserts focus (toHaveFocus); first rule: Tab moves through the bar items in DOM order
Display modes (forced colours, 320px reflow, text spacing, reduced motion)passn/apassthe four sweep projects (storybook-forced-colors, -reduced-motion, -reflow, -text-spacing), run in CI
Core (required for beta)
NVDA + Chrome + Windowspendingpendingpending
VoiceOver + Safari + iOSpendingpendingpending
Release (before 1.0 and each minor)
JAWS + Chrome + Windowspendingpendingpending
TalkBack + Chrome + Androidpendingpendingpending
VoiceOver + Safari + macOSpendingpendingpending

What to check#

With a screen reader and the keyboard, try:

  • Tab goes through the bar in the order it is read: text links first, the tools last.
  • The landmarks list does not show the bar. It shows its navigation, with its own name.
  • The current tool is announced as current.
  • A link-look button is announced as a button, and Enter and Space both press it.
  • At 320px the two sides wrap, nothing is hidden, and there is no sideways scroll.
  • On a filled bar in a high-contrast theme or forced colours, the text and the focus ring stay easy to see.