Tabs
BasicNavigation
<co-tabs>Tabs switch between views of the same record or list: line tabs under a header, or pill tabs, both with optional counts.
import { Tabs } from 'health-components';
Examples
Variants
With Panels
Usage
<Tabs items={[{ id: "o", label: "Overview" }, { id: "l", label: "Lines", count: 3 }]} value={tab} onChange={setTab} />
When to use
- Views of one thing: claim Overview, Lines, History; queue All, Mine, Overdue.
When not to use
- Moving through steps: Stepper.
- Separate screens in a chart: SectionNav.
Variants and states
| Variant | What it is |
|---|---|
| line | Default, under page or card titles. |
| pill | Inside cards and toolbars. |
| counts | Number per tab; alert makes it red. |
| disabled | Not available to this role. |
Accessibility
- tablist, tab, aria-selected; arrow keys move between tabs (roving tabindex).
- Home and End jump to the first and last tab; disabled tabs are skipped. Give items a
panelIdto set aria-controls; each tab's id is<id>-<item.id>for the panel's aria-labelledby.
Do and don't
- Do: "Needs Review 4" as a count, red when overdue.
- Don't: Tabs that submit or save.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
items * | TabItem[] | — | The tabs. Required. |
value | string | uncontrolled | Selected tab id (controlled) |
defaultValue | string | the first tab | Initially selected tab id |
variant | TabsVariant | 'line' | 'line' under page or card titles, 'pill' inside cards and toolbars |
label | string | none | aria-label of the tablist |
onChange | (id: string) => void | none | Called with the new tab id |
Also accepts native attributes, including defaultChecked, autoFocus, plus className and event handlers on the root element.
Angular, Vue and HTML
Register the elements once (Angular guide), then use <co-tabs>. 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-tabs value="…" default-value="…" [items]="items" (co-change)="onChange($event.detail)"></co-tabs>
| Kind | Name | Description |
|---|---|---|
| property / JSON attribute | items | The tabs. Required. |
| attribute | value | Selected tab id (controlled); default uncontrolled |
| attribute | default-value / defaultValue | Initially selected tab id; default the first tab |
| attribute | variant | 'line' under page or card titles, 'pill' inside cards and toolbars; default 'line' |
| attribute | label | aria-label of the tablist; default none |
| attribute | default-checked / defaultChecked | |
| attribute | auto-focus / autoFocus | |
| event | co-change | Called with the new tab id; default none (React: onChange) |