Skip to main content

SegmentedControl

BasicSelection<co-segmented-control>

SegmentedControl switches between two to five views or values in one compact bar.

import { SegmentedControl } from 'health-components';

Examples​

Showcase​

Storybook

Small​

Storybook

With Disabled Option​

Storybook

Usage​

<SegmentedControl label="Calendar view" options={["Day", "Week", "Month"]} value={view} onChange={setView} />

When to use​

  • View switches: Upcoming, Past; Day, Week, Month; Comfortable, Compact.

When not to use​

  • More than five options or long labels: Tabs or Select.

Variants and states​

VariantWhat it is
md34px segments.
sm26px, dense toolbars.
countsNumber after the label.

Accessibility​

  • radiogroup with radio buttons and aria-checked.

Do and don't​

  • Do: Density: Comfortable, Compact.
  • Don't: Use it to submit.

Props​

PropTypeDefaultDescription
options *ReadonlyArray<string | SegmentedOption>—Two to five options: strings or `{value, label, count?, disabled?}`. Required
valuestringfirst optionSelected value (controlled)
defaultValuestringfirst optionInitially selected value (uncontrolled)
size'sm' | 'md''md''sm' | 'md'
labelstringnoneAccessible name of the group (aria-label)
onChange(value: string) => voidnoneCalled with the newly selected value

Also accepts native attributes, including defaultChecked, autoFocus, onInput, plus className and event handlers on the root element.

Angular, Vue and HTML​

Register the elements once (Angular guide), then use <co-segmented-control>. Attributes take strings; arrays and objects are set as properties (Angular [prop], Vue :prop) or as JSON attributes. Callbacks are DOM events with the value in event.detail.

Angular template
<co-segmented-control value="…" default-value="…" [options]="options" (co-change)="onChange($event.detail)"></co-segmented-control>
KindNameDescription
property / JSON attributeoptionsTwo to five options: strings or `{value, label, count?, disabled?}`. Required
attributevalueSelected value (controlled); default first option
attributedefault-value / defaultValueInitially selected value (uncontrolled); default first option
attributesize'sm' | 'md'; default 'md'
attributelabelAccessible name of the group (aria-label); default none
attributedefault-checked / defaultChecked
attributeauto-focus / autoFocus
eventco-changeCalled with the newly selected value; default none (React: onChange)
eventco-input (React: onInput)