# Tabs

Switches between views of the same thing, without leaving the page.

```tsx
import { Tabs, TabList, Tab, TabPanel } from '@halo-ds/react';
```

## When to use it
Use tabs to split related content into sections that people move between, like Overview, Activity and Settings. Tab is one tab; Tabs holds a row or column of them in a slot, laid out Horizontal, Full width or Vertical, in a Line or Pill style.

## Do
- Write short labels of one or two words.
- Select the most useful tab by default, usually the first.
- Keep the tabs in the same place when the content changes.
- Use a Badge for counts, like new comments.

## Don't
- Nest tabs inside tabs; it is hard to follow.
- Mix Line and Pill tabs on one page.
- Use tabs for steps people must do in order.
- Hide a tab that has no content; show an Empty state inside it.

## Tabs or Navigation?
Both move people around. Pick by whether they stay on the same page.
- **Tabs**: Switch between views of the same thing, like a project. The content swaps in place; the page and URL stay the same. Keep it to about 2 to 7 tabs.
- **Navigation or Menu**: Navigation: go to a different page or part of the app. Menu or Select: act on the content or filter it. Don't use tabs as steps; use a Stepper.

## Props
### Tabs props
| Prop | Type | What it does |
| --- | --- | --- |
| `value` | `string \| undefined` |  |
| `defaultValue` | `string \| undefined` |  |
| `onValueChange` | `((value: string) => void) \| undefined` |  |
| `variant` | `"line" \| "pill" \| undefined` | line has an underline; pill has a grey pill. Figma: Style. |
| `size` | `"sm" \| "md" \| undefined` | 32 or 40px tall. Figma: Size. |
| `layout` | `"vertical" \| "horizontal" \| "fullWidth" \| undefined` | horizontal, fullWidth (tabs share the width) or vertical (list on the left). Figma: Layout. |
| `classNames` | `Partial<Record<TabsPart, string>> \| undefined` | Extra class names for the parts inside the component, by part name, like `{ header: 'my-header' }`. |
| `styles` | `Partial<Record<TabsPart, CSSProperties>> \| undefined` | Inline styles for the parts inside the component, by part name, like `{ footer: { gap: 4 } }`. |
It also takes the usual HTML attributes for its element.

### TabList props
| Prop | Type | What it does |
| --- | --- | --- |
| `aria-label` | `string \| undefined` | Names the set of tabs for screen readers. |
It also takes the usual HTML attributes for its element.

### Tab props
| Prop | Type | What it does |
| --- | --- | --- |
| `value` (required) | `string` |  |
| `icon` | `ReactNode` | Icon before the label. Figma: L icon. |
| `badge` | `ReactNode` | A count or short label after the text. Figma: Badge. |
| `disabled` | `boolean \| undefined` |  |
It also takes the usual HTML attributes for its element.

### TabPanel props
| Prop | Type | What it does |
| --- | --- | --- |
| `value` (required) | `string` |  |
| `keepMounted` | `boolean \| undefined` | Keep the panel in the page when hidden, to save its state. |
It also takes the usual HTML attributes for its element.

## Examples
### Overview
```tsx
import { Tab, TabList, TabPanel, Tabs } from '@halo-ds/react';

export default function Example() {
  return (
    <div style={{ width: '100%', maxWidth: 480 }}>
      <Tabs defaultValue="overview">
        <TabList aria-label="Project">
          <Tab value="overview">Overview</Tab>
          <Tab value="activity">Activity</Tab>
          <Tab value="settings">Settings</Tab>
        </TabList>
        <TabPanel value="overview" style={{ paddingTop: 16 }}>Everything about the project at a glance.</TabPanel>
        <TabPanel value="activity" style={{ paddingTop: 16 }}>Who changed what, and when.</TabPanel>
        <TabPanel value="settings" style={{ paddingTop: 16 }}>Name, members and permissions.</TabPanel>
      </Tabs>
    </div>
  );
}
```

### Pill
A grey pill behind the selected tab.
```tsx
import { Tab, TabList, Tabs } from '@halo-ds/react';

export default function Demo() {
  return (
    <Tabs variant="pill" defaultValue="overview">
      <TabList aria-label="Project">
        <Tab value="overview">Overview</Tab>
        <Tab value="activity">Activity</Tab>
        <Tab value="members" badge={8}>Members</Tab>
      </TabList>
    </Tabs>
  );
}
```

### Icons, badges and disabled
An icon before the label, a count after it, and a tab that can not be chosen yet.
```tsx
import { Tab, TabList, Tabs } from '@halo-ds/react';
import { ChartBar, Gear, House, Users } from '@phosphor-icons/react';

export default function Demo() {
  return (
    <Tabs defaultValue="overview">
      <TabList aria-label="Project">
        <Tab value="overview" icon={<House />}>Overview</Tab>
        <Tab value="activity" icon={<ChartBar />}>Activity</Tab>
        <Tab value="members" icon={<Users />} badge={8}>Members</Tab>
        <Tab value="settings" icon={<Gear />} disabled>Settings</Tab>
      </TabList>
    </Tabs>
  );
}
```

### Full width
The tabs share the full width, good for phones.
```tsx
import { Tab, TabList, Tabs } from '@halo-ds/react';

export default function Demo() {
  return (
    <div style={{ width: '100%', maxWidth: 420 }}>
      <Tabs layout="fullWidth" defaultValue="all">
        <TabList aria-label="Messages">
          <Tab value="all">All</Tab>
          <Tab value="unread">Unread</Tab>
          <Tab value="sent">Sent</Tab>
        </TabList>
      </Tabs>
    </div>
  );
}
```

### Vertical
The list sits on the left. Up and Down arrows move between tabs.
```tsx
import { Tab, TabList, TabPanel, Tabs } from '@halo-ds/react';

export default function Demo() {
  return (
    <Tabs layout="vertical" defaultValue="profile">
      <TabList aria-label="Settings">
        <Tab value="profile">Profile</Tab>
        <Tab value="security">Security</Tab>
        <Tab value="billing">Billing</Tab>
      </TabList>
      <TabPanel value="profile" style={{ padding: 16 }}>Name, photo and bio.</TabPanel>
      <TabPanel value="security" style={{ padding: 16 }}>Password and two-step sign-in.</TabPanel>
      <TabPanel value="billing" style={{ padding: 16 }}>Plan, card and invoices.</TabPanel>
    </Tabs>
  );
}
```

### Small
32px tabs for dense panels.
```tsx
import { Tab, TabList, Tabs } from '@halo-ds/react';

export default function Demo() {
  return (
    <Tabs size="sm" defaultValue="day">
      <TabList aria-label="Range">
        <Tab value="day">Day</Tab>
        <Tab value="week">Week</Tab>
        <Tab value="month">Month</Tab>
      </TabList>
    </Tabs>
  );
}
```

More: https://halodesignsystem.dev/components/tabs
