Skip to Content
BBRICKSv0.7.4
KitForms

Segmented

A labelled single choice drawn as the mock's .seg (7 / 30 / 90 days, Chart / Table). A radiogroup like FilterChips (B10: it was a group of pressed buttons): one tab stop on the chosen option, the arrows move and choose (Left / Right mirrored in RTL), Home / End jump to the ends. size="sm" is the v3 mock's compact .seg (13px text, 7px 14px segments, 33px tall, in a 1px-bordered 41px track), for a scope switch in a toolbar or a card head.

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

Examples

Range picker

A radio group drawn as one pill; arrow keys move and select. Options are [value, label] pairs and the value type is inferred.

Code
import { useState } from 'react';
import { Segmented } from '@ergasti/bricks';

function Range() {
  const [range, setRange] = useState<'7' | '30' | '90'>('30');
  return <Segmented label="Range" value={range} onChange={setRange} options={[['7', '7 days'], ['30', '30 days'], ['90', '90 days']]} />;
}

Disabled

Code
import { Segmented } from '@ergasti/bricks';

function Disabled() {
  return <Segmented label="Range" value="7" onChange={() => {}} disabled options={[['7', '7 days'], ['30', '30 days']]} />;
}

Small size

size="sm" is the compact pill (13px text, 33px segments inside a 1px-bordered, 41px track) for a scope switch in a toolbar or a card header; the default md follows the surrounding text size.

Code
import { useState } from 'react';
import { Segmented } from '@ergasti/bricks';

function Small() {
  const [scope, setScope] = useState<'my' | 'all'>('my');
  return <Segmented size="sm" label="Brands shown" value={scope} onChange={setScope} options={[['my', 'My brands'], ['all', 'All brands']]} />;
}

Props

Prop

Type

Design guidance

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

A pill-shaped single-choice control (7 / 30 / 90 days, My brands / All brands); use it to switch the scope or range of what a screen shows.

Segmented is the mock's .seg: options as pill segments on a soft track, the chosen one raised on the card colour. It is a radiogroup with one tab stop on the chosen option; the arrow keys move and choose (Left/Right mirrored in RTL) and Home/End jump to the ends. size="sm" is the v3 mock's compact switch for toolbars and card heads.

Anatomy

  1. Track (div.kit-seg, role="radiogroup", aria-label): 3px padding, pill radius, --seg-track (default --soft).
  2. Segments (button, role="radio", aria-checked): 600 weight, --ink-3 text, padding --seg-pad (6px 14px).
  3. Selected segment: --seg-on-bg (card) background, --seg-on-ink (ink) text, small shadow.

Variants

sizeLookWhen
'md' (default)6px 14px segments, inherited font sizePage toolbars (Analytics range)
'sm'13px text, 7px 14px, 33px segments in a 1px-bordered 41px trackCard heads, PR scope switches

States

StateTriggerLook
Selectedvalue equals the optionRaised segment
No matchvalue matches noneNothing raised; the first option is the tab stop
Hoverpointer—
Focus-visiblekeyboardShared kit focus ring on the segment
PressedclickScales to 0.98 (off under reduced motion)
DisableddisabledAll segments disabled, keys ignored, aria-disabled on the group
Touch≤1024pxSegments 44px min height

Usage

The Analytics toolbar:

function AnalyticsToolbar() {
  const [range, setRange] = useState('30');
  const [challenge, setChallenge] = useState('all');
  return (
    <Toolbar
      filters={<>
        <Segmented label="Range" value={range} onChange={(value) => setRange(value)}
          options={[['7', '7 days'], ['30', '30 days'], ['90', '90 days']]} />
        <SelectBox id="an-challenge" label="Challenge" hideLabel value={challenge} onChange={(value) => setChallenge(value)}
          options={[['all', 'All challenges'], ['winter', 'Winter glow launch'], ['campus', 'Back to campus']]} />
      </>}
      actions={<Button size="sm">Export CSV</Button>}
    />
  );
}

A PR Portal scope switch in the page header:

<PageHeader title="Gift analytics"
  actions={<Segmented size="sm" label="Brands to show" value={scope} onChange={setScope}
    options={[['mine', 'My brands'], ['all', 'All brands']]} />} />

Where it appears

Guidelines

Do

  • Use 2 to 4 short options.
  • Apply the choice immediately.

Don't

  • Don't use it to navigate between pages (use PillTabs).
  • Don't use it for multi-select filters (use FilterChips).

RTL and Arabic

  • Options flow right to left in Arabic and Left/Right arrows swap meaning.

Tokens

--seg-track, --seg-line, --seg-pad, --seg-fs, --seg-on-bg, --seg-on-ink, --seg-on-shadow, --soft, --card, --ink, --ink-3, --min-touch-target. The PR theme sets the --seg-* values.

Accessibility

  • Role and name: a radiogroup named by label; each segment is a native <button role="radio" aria-checked>.
  • One Tab stop (roving tab index): the chosen segment, or the first one when value matches no option, so the group is always reachable.
  • Keys: Left/Right step and choose at once (swapped in RTL), Up/Down step too, every arrow wraps at the ends, Home/End jump to the first/last. Space or Enter on a focused segment chooses it.
  • Selection is spoken as "checked" (radio semantics), not only shown by the raised segment.
  • Focus: the shared kit ring (--focus-ring) on the segment.
  • Disabled: every segment is disabled and the group gets aria-disabled; keys do nothing.
  • Hit area: segments grow to 44px tall on touch screens (≤1024px).

Found in the source

  • Roles in the markup: radiogroup, radio.
  • ARIA attributes set: aria-label, aria-disabled, aria-checked.
  • It moves focus in code.

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

See also: FormField · SaveBar · SearchBox

Source

src/kit/Segmented.tsx (line 11) on GitHub.

On this page