Skip to main content

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​

Storybook

With Panels​

Storybook

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​

VariantWhat it is
lineDefault, under page or card titles.
pillInside cards and toolbars.
countsNumber per tab; alert makes it red.
disabledNot 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 panelId to 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​

PropTypeDefaultDescription
items *TabItem[]—The tabs. Required.
valuestringuncontrolledSelected tab id (controlled)
defaultValuestringthe first tabInitially selected tab id
variantTabsVariant'line''line' under page or card titles, 'pill' inside cards and toolbars
labelstringnonearia-label of the tablist
onChange(id: string) => voidnoneCalled 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>
KindNameDescription
property / JSON attributeitemsThe tabs. Required.
attributevalueSelected tab id (controlled); default uncontrolled
attributedefault-value / defaultValueInitially selected tab id; default the first tab
attributevariant'line' under page or card titles, 'pill' inside cards and toolbars; default 'line'
attributelabelaria-label of the tablist; default none
attributedefault-checked / defaultChecked
attributeauto-focus / autoFocus
eventco-changeCalled with the new tab id; default none (React: onChange)