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
Small
With Disabled Option
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
| Variant | What it is |
|---|---|
| md | 34px segments. |
| sm | 26px, dense toolbars. |
| counts | Number 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
| Prop | Type | Default | Description |
|---|---|---|---|
options * | ReadonlyArray<string | SegmentedOption> | — | Two to five options: strings or `{value, label, count?, disabled?}`. Required |
value | string | first option | Selected value (controlled) |
defaultValue | string | first option | Initially selected value (uncontrolled) |
size | 'sm' | 'md' | 'md' | 'sm' | 'md' |
label | string | none | Accessible name of the group (aria-label) |
onChange | (value: string) => void | none | Called 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>
| Kind | Name | Description |
|---|---|---|
| property / JSON attribute | options | Two to five options: strings or `{value, label, count?, disabled?}`. Required |
| attribute | value | Selected value (controlled); default first option |
| attribute | default-value / defaultValue | Initially selected value (uncontrolled); default first option |
| attribute | size | 'sm' | 'md'; default 'md' |
| attribute | label | Accessible name of the group (aria-label); default none |
| attribute | default-checked / defaultChecked | |
| attribute | auto-focus / autoFocus | |
| event | co-change | Called with the newly selected value; default none (React: onChange) |
| event | co-input | (React: onInput) |