Skip to content

Tabs

Tab navigation component for switching between views.

Also known as: tab bar, tab navigation, segmented control, tab switcher

View in Storybook

When to use

  • Switching between views or content sections. For step-by-step flows, use Stepper.

Import

tsx
import { Tabs } from '@vacano/ui'

Usage

tsx
const [activeTab, setActiveTab] = useState('overview')

const tabs = [
  { value: 'overview', label: 'Overview' },
  { value: 'analytics', label: 'Analytics' },
  { value: 'settings', label: 'Settings' },
]

<Tabs
  value={activeTab}
  tabs={tabs}
  onChange={setActiveTab}
/>

With Disabled Tab

tsx
const tabs = [
  { value: 'active', label: 'Active' },
  { value: 'disabled', label: 'Disabled', disabled: true },
  { value: 'another', label: 'Another' },
]

<Tabs value="active" tabs={tabs} onChange={setActiveTab} />

Full Example with Content

tsx
const [activeTab, setActiveTab] = useState('tab1')

<div>
  <Tabs
    value={activeTab}
    tabs={[
      { value: 'tab1', label: 'Tab 1' },
      { value: 'tab2', label: 'Tab 2' },
      { value: 'tab3', label: 'Tab 3' },
    ]}
    onChange={setActiveTab}
  />

  <div style={{ marginTop: 16 }}>
    {activeTab === 'tab1' && <p>Content for Tab 1</p>}
    {activeTab === 'tab2' && <p>Content for Tab 2</p>}
    {activeTab === 'tab3' && <p>Content for Tab 3</p>}
  </div>
</div>

Props

PropTypeDefaultDescription
valuestringrequiredActive tab value
tabsTabItem[]requiredArray of tabs
onChange(value: string) => voidrequiredChange handler
refRef<HTMLDivElement>-Forwarded ref
classNamestring-CSS class name for the root element
classnamesTabsClassNames-Custom class names for sub-elements

TabItem

PropertyTypeDefaultDescription
valuestringrequiredUnique tab identifier
labelstringrequiredTab display label
disabledbooleanfalseDisable this tab

ClassNames

KeyDescription
tabIndividual tab button
  • Stepper - Multi-step flow indicator

Released under the MIT License.