Skip to content

Segmented bar

Pro

One whole in a few parts, as a bar that prints its figures or a thin bar above a list of the parts; parts with an order can take the theme's ramp, lightest to darkest (the reverse in dark mode). Not an M3 component (@windmorph/react-pro).

import { SegmentedBar, SegmentedList } from '@windmorph/react-pro/charts';

Part of Windmorph Pro, paid components on the free core, not on sale yet. See the Pro guide for what it includes and to register interest.

Keyboard

Segmented bar keyboard
KeyAction
Arrow Right or Arrow UpReads the next part.SegmentedBar
Arrow Left or Arrow DownReads the part before.SegmentedBar
Home or EndReads the first or the last part.SegmentedBar
Page Up or Page DownMoves a tenth of the parts, at least one: with six parts or fewer, one part.SegmentedBar
EscapeHides the readout, wherever focus is for one the pointer shows. It shows again on another part (a key or the pointer), once the pointer leaves and comes back, or when the bar takes focus again. With no readout showing, Escape goes on, so a dialog round the bar still closes.SegmentedBar
  • Right to left, Arrow Left reads the next part and Arrow Right the one before, as the parts run from the right.
  • Tabbing to the bar reads its first part and shows the readout, and the keys start there; after a press or a tap they go on from the part pressed.
  • SegmentedList has no keys: its rows are text, with nothing to focus.

Screen reader

Role
SegmentedBar: a slider (a native range input, unseen, over the parts), then the key, a list named labels.parts ("Parts") and the bar’s name. SegmentedList: a list, one item per part.
Accessible name
Named by aria-label or aria-labelledby, or in a ChartFrame by its title; a development build warns about one with no name.
States announced
The slider’s value text (aria-valuetext) is the part it reads, then where it is among the parts: "Phone: 5,120, 59%, 1 of 3", from labels.describePart. With no parts it says labels.noValue ("No value") and is aria-disabled, still focusable, so focus on it never drops to the page. Each list row reads its name, share and amount apart ("Web, 60%, 600").
  • The blocks, the shares printed on them, the colour keys and the readout are hidden from assistive tech (aria-hidden); the value text, the key's names and the list's rows say the same.
  • A screen reader's step (a swipe up or down, or a volume key) moves the slider as a key does, since it is a native input.
  • An amount that isn’t a number reads labels.noValue, never "NaN".
  • The value text follows the keys and a screen reader’s own steps, never the pointer hovering a focused bar.

Focus

  • A SegmentedBar is one tab stop. Keyboard focus draws the M3 focus indicator round the bar and shows the readout of the part it reads.
  • A press or a tap on a part reads it and moves focus to the bar, without scrolling, so the arrow keys go on from that part.
  • A SegmentedList adds no tab stops.

Touch target

  • The bar is 28px tall (--wm-segmented-height), under 48px: it is read, never pressed to act, and a finger can slide along it. Everything it shows is also in the key, the value text and a frame's table view; raise the token where fingers need a taller bar.
  • A SegmentedList has nothing to press.

Motion

  • The parts grow to their shares when the bar first comes into view, and move to new shares when they change, on the default spatial spring. Under reduced motion they take their shares at once.
  • While one part is read the others step back, dimming their colour on the fast effects spring, under reduced motion too: a fade is not movement.
  • A bar on screen as the page hydrates shows its shares from the server's HTML and doesn't replay.

What you need to do

  • Name each bar or list with aria-label ("Visits by device"), or put it in a ChartFrame, whose title names it.
  • Keep to two to five parts, largest first, so anything past six folds the smallest into "Other". Labels are text, never HTML.
  • Use ordered only for parts with an order, and keep them to five.
  • Keep texture on (it is, for two or more parts) where colour may not be told apart; the key names every part either way.
  • In forced-colours mode the patterns are always drawn: each part is Canvas with a CanvasText edge and its pattern in CanvasText (the first slot or step a solid CanvasText block, "Other" dotted), a share printed on a part sits on a Canvas patch, and the colour keys (in the key, the readout and a SegmentedList’s rows) carry the same patterns, so a part is matched to its name without colour.
  • Translate labels.describePart, labels.parts, labels.other, labels.noValue, labels.listSeparator (what screen readers hear between a SegmentedList row’s name, share and amount, ", " by default) and the table view’s column headers (labels.part, labels.amount and labels.share), or set them once for the app with a LabelsProvider (its Chart words).