# Tabs

Underline tabs from the opportunity and contact workspaces: 12 px labels with a 14 px icon, and an orange underline that slides to the selected tab. Built on ui-sdk's Tabs: arrow keys move between tabs and select them, Home and End jump to the ends.

- Beta: ready to use; its API can still change in a minor release.
- Category: Navigation

```tsx
import { UnderlineTabs, Tabs, TabsList, TabsTab, TabsPanels, TabsPanel } from "@leap-crm/design-system";
```

## Best practices

- Do: Use `UnderlineTabs` for workspace sections driven by `value`, like an opportunity's Overview, Tasks and Notes. Compose `Tabs`, `TabsList`, `TabsTab` and `TabsPanel` when each tab owns its content.
- Do: Put the panels in `TabsPanels`, so switching slides the new panel in and the height eases instead of jumping the content below.
- Do: Name the list with `aria-label`, like "Opportunity sections".
- Do: Leave `count` out while it's unknown. A count that shows 0 while loading tells a lawyer there are no open tasks.
- Don't: Use tabs to switch between views of the same data, like a list and a board. Use `ViewSwitch`, or `SegmentedControl` for a choice in a form or filter.

## Keyboard

| Keys | What they do |
| --- | --- |
| Tab | Moves focus to the selected tab, then from the tab list into its panel. |
| ArrowRight, ArrowLeft | Move focus and select the tab. |
| Home, End | Move to the first and last tabs. |
| Shift + Tab | From the panel, returns to the selected tab. |

## Related

- [Segmented Control](./segmented-control.md)
- [View Switch](./view-switch.md)
- [Breadcrumbs](./breadcrumbs.md)
- [Collapsible](./collapsible.md)

## Examples

What the examples import:

```tsx
import { Eye, FileText, Link, ListTree, Phone, SquareCheckBig, StickyNote } from "lucide-react";
import { useState } from "react";
import { Tabs, TabsList, TabsPanel, TabsPanels, TabsTab, UnderlineTabs, type TabItem } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const workspace = [
  { value: "overview", label: "Overview", icon: Eye },
  { value: "tasks", label: "Tasks", icon: SquareCheckBig, count: 3 },
  { value: "notes", label: "Notes", icon: StickyNote },
  { value: "documents", label: "Documents", icon: FileText, count: 12 },
  { value: "relationships", label: "Relationships", icon: Link },
  { value: "interactions", label: "Interactions", icon: Phone },
  { value: "extra-fields", label: "Extra Fields", icon: ListTree },
] as const satisfies readonly TabItem[];

type Section = (typeof workspace)[number]["value"];

function WorkspaceTabs() {
  const [value, setValue] = useState<Section>("overview");
  return (
    <UnderlineTabs
      aria-label="Opportunity sections"
      tabs={workspace}
      value={value}
      onValueChange={setValue}
    />
  );
}
```

### Workspace tabs

UnderlineTabs takes the CRM's tab list as it is: value, label, icon, count. Click or use the arrow keys; the underline slides along.

```tsx
<WorkspaceTabs />
```

### With panels

Compose Tabs, TabsList, TabsTab and TabsPanel when each tab owns content, with the panels in TabsPanels so switching turns the page: the new panel slides in toward the tab you picked while the old one crossfades out, and the height eases between panels of different lengths. Reduced motion only crossfades. Tab from the list moves into the selected panel.

```tsx
<Tabs defaultValue="tasks" className="flex w-full flex-col gap-4">
  <TabsList aria-label="Contact sections">
    <TabsTab value="overview" icon={<Eye />}>
      Overview
    </TabsTab>
    <TabsTab value="tasks" icon={<SquareCheckBig />} count={3}>
      Tasks
    </TabsTab>
    <TabsTab value="notes" icon={<StickyNote />}>
      Notes
    </TabsTab>
  </TabsList>
  <TabsPanels>
    <TabsPanel value="overview" className="text-body p-2">
      Jane Citizen prefers email and is reviewing the costs agreement.
      She asked for a call back after 3 pm on weekdays, and her matter
      is waiting on the signed agreement.
    </TabsPanel>
    <TabsPanel
      value="tasks"
      className="text-body flex flex-col gap-2 p-2"
    >
      <span>Send the costs agreement, due today.</span>
      <span>Call about the title search, due Wednesday.</span>
      <span>Book the settlement date, due Friday.</span>
    </TabsPanel>
    <TabsPanel value="notes" className="text-body p-2">
      No notes yet.
    </TabsPanel>
  </TabsPanels>
</Tabs>
```

### States

Selected (orange underline, #ad6430 label at 450), unselected, hover (darker label) and disabled. Tab to see focus wrap the whole tab, underline included.

```tsx
<Tabs defaultValue="selected">
  <TabsList aria-label="States">
    <TabsTab value="selected" icon={<Eye />}>
      Selected
    </TabsTab>
    <TabsTab value="unselected" icon={<Eye />}>
      Unselected
    </TabsTab>
    <TabsTab value="count" icon={<FileText />} count={12}>
      With count
    </TabsTab>
    <TabsTab value="disabled" icon={<Eye />} disabled>
      Disabled
    </TabsTab>
  </TabsList>
</Tabs>
```

## Props

Tabs takes ui-sdk's Tabs options: value, defaultValue, onValueChange, orientation, activation (automatic or manual), loop and controller. TabsTab takes value, disabled and render.

### UnderlineTabs

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `tabs` (required) | `unknown` |  | The tabs, in order: value, label, and an optional count, icon or link. |
| `value` (required) | `TValue` |  | The selected tab's value. |
| `onValueChange` | `(value: TValue) => void` |  | Runs with the tab's value when another is selected. |
| `aria-label` | `string` |  | Names the tab list for screen readers, like "Opportunity sections". |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
| `tabClassName` | `string` |  | Classes for every tab. |

### TabsList

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### TabsTab

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `icon` | `ReactNode` |  | A 14 px icon before the label. It takes the tab's colour. |
| `count` | `number` |  | A small count after the label, like the number of open tasks. Leave it out while it's unknown. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### TabsPanels

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | The TabsPanels, one per tab. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |

### TabsPanel

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
