Tabs

A set of tabs with an active index.

Pass Tab elements as children. theme sets the appearance: line (default), pill, or pill-secondary. index enables controlled mode, defaultIndex sets the initial tab. onChange receives the index and the event; it also fires on keyboard navigation with arrows, Home, and End. The markup uses the tablist, tab, and tabpanel roles.

Live example

Content for "One" tab

Example controls

Usage

import { Tab, Tabs } from '@prosazhin/pbcomponents';

<Tabs
  defaultIndex={0}
  theme='pill'
>
  {['One', 'Two', 'Three', 'Four', 'Five'].map((label) => (
    <Tab
      key={label}
      label={label}
    >
      <div style={{ marginTop: 24 }}>{`Content for "${label}" tab`}</div>
    </Tab>
  ))}
</Tabs>;

Component API

PropType / variantsPurposeDefault
childrenTab[]Tabs with labels and content.—
theme'line' | 'pill' | 'pill-secondary'line · pill · pill-secondaryTabs appearance; passed to every Tab.line
indexnumberActive tab in controlled mode.—
defaultIndexnumber0 · 1 · 2 · 3 · 4Initial active tab index.0
onChange(index: number, event: MouseEvent | KeyboardEvent) => voidCalled when a tab is chosen with the mouse or with arrows, Home and End.—
classNamestringClass of the root element.—

Native HTML attributes are accepted where the component renders the corresponding element. className props only affect styling.