> For the complete documentation index, see [llms.txt](https://docs.rierino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rierino.com/sdk-core-ui/components/tabs.md). Agents can also search and read this documentation through its [MCP server](https://docs.rierino.com/~gitbook/mcp).

# Tabs

Splits related content into panels and shows one at a time.

{% code title="tabs/demo.tsx" %}

```tsx
import { Tab, TabList, TabPanel, Tabs } from "@rierino-open/core-ui";

const panel = { padding: "16px 4px", fontSize: 13 };

export default function TabsDemo() {
  return (
    <div style={{ width: "100%", maxWidth: 560 }}>
      <Tabs>
        <TabList aria-label="Product">
          <Tab id="details">Details</Tab>
          <Tab id="pricing">Pricing</Tab>
          <Tab id="inventory">Inventory</Tab>
        </TabList>
        <TabPanel id="details" style={panel}>
          Name, description and images.
        </TabPanel>
        <TabPanel id="pricing" style={panel}>
          Prices per channel and currency.
        </TabPanel>
        <TabPanel id="inventory" style={panel}>
          Stock levels per warehouse.
        </TabPanel>
      </Tabs>
    </div>
  );
}
```

{% endcode %}

## Usage

{% tabs %}
{% tab title="React app" %}

```tsx
import { Tab, TabList, TabPanel, Tabs } from '@rierino-open/core-ui';

<Tabs>
  <TabList aria-label="Product">
    <Tab id="details">Details</Tab>
    <Tab id="pricing">Pricing</Tab>
  </TabList>
  <TabPanel id="details">…</TabPanel>
  <TabPanel id="pricing">…</TabPanel>
</Tabs>
```

{% endtab %}

{% tab title="Hosted editor" %}

```jsx
import CoreUI from '@rierino-open/core-ui';
const { Tab, TabList, TabPanel, Tabs } = CoreUI;

<Tabs>
  <TabList aria-label="Product">
    <Tab id="details">Details</Tab>
    <Tab id="pricing">Pricing</Tab>
  </TabList>
  <TabPanel id="details">…</TabPanel>
  <TabPanel id="pricing">…</TabPanel>
</Tabs>
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
**Give every Tab and TabPanel an id**

A tab shows the `TabPanel` with the same `id`. Without ids the tabs still switch, but no panel is shown at all.
{% endhint %}

`Tabs` holds the selection, `TabList` holds the tabs, and each `TabPanel` holds the content for the tab with its `id`. The first tab is selected unless you set one. Only the selected panel is rendered.

## Examples

### Controlled selection

Use `selectedKey` and `onSelectionChange` to know which tab is open, or to switch tabs from code. `onSelectionChange` is also called once on mount with the first tab, when no tab is set.

{% code title="tabs/controlled.tsx" %}

```tsx
import { useState } from "react";
import type { Key } from "react-aria-components";
import { Tab, TabList, TabPanel, Tabs } from "@rierino-open/core-ui";

const panel = { padding: "16px 4px", fontSize: 13 };

export default function TabsControlled() {
  const [tab, setTab] = useState<Key>("orders");

  return (
    <div style={{ width: "100%", maxWidth: 560, display: "grid", gap: 8 }}>
      <Tabs selectedKey={tab} onSelectionChange={setTab}>
        <TabList aria-label="Customer">
          <Tab id="orders">Orders</Tab>
          <Tab id="addresses">Addresses</Tab>
          <Tab id="notes">Notes</Tab>
        </TabList>
        <TabPanel id="orders" style={panel}>12 orders</TabPanel>
        <TabPanel id="addresses" style={panel}>2 addresses</TabPanel>
        <TabPanel id="notes" style={panel}>No notes yet</TabPanel>
      </Tabs>
      <span style={{ fontSize: 12 }}>Selected: {String(tab)}</span>
    </div>
  );
}
```

{% endcode %}

### Vertical

`orientation="vertical"` puts the tabs in a column beside the panel. The arrow keys become `↑` and `↓`.

{% code title="tabs/vertical.tsx" %}

```tsx
import { Tab, TabList, TabPanel, Tabs } from "@rierino-open/core-ui";

const panel = { padding: "10px 20px", fontSize: 13 };

export default function TabsVertical() {
  return (
    <div style={{ width: "100%", maxWidth: 560 }}>
      {/* Vertical tabs are 800px wide by default; className="w-full" fits them to the container.
          The div around TabList keeps the tab column as narrow as its tabs. */}
      <Tabs orientation="vertical" className="w-full">
        <div style={{ flex: "none" }}>
          <TabList aria-label="Settings">
            <Tab id="general">General</Tab>
            <Tab id="channels">Channels</Tab>
            <Tab id="taxes">Taxes</Tab>
          </TabList>
        </div>
        <TabPanel id="general" style={panel}>Store name, language and currency.</TabPanel>
        <TabPanel id="channels" style={panel}>Web store, mobile app and marketplaces.</TabPanel>
        <TabPanel id="taxes" style={panel}>Tax rates per country.</TabPanel>
      </Tabs>
    </div>
  );
}
```

{% endcode %}

Vertical tabs are 800px wide by default. Pass `className="w-full"`, or your own width, to fit them to their container. The tab column also stretches to the full width, pushing the panel to the far side. Wrap `TabList` in a `div` with `style={{ flex: "none" }}` to keep the column as narrow as its tabs, as above.

### Disabled tabs

Disable some tabs with `disabledKeys` on `Tabs`, or `isDisabled` on a `Tab`. `isDisabled` on `Tabs` disables all of them. Disabled tabs are dimmed, show a not-allowed cursor, ignore clicks and are skipped by the keyboard.

{% code title="tabs/disabled.tsx" %}

```tsx
import { Tab, TabList, TabPanel, Tabs } from "@rierino-open/core-ui";

const panel = { padding: "16px 4px", fontSize: 13 };

export default function TabsDisabled() {
  return (
    <div style={{ width: "100%", maxWidth: 560 }}>
      <Tabs disabledKeys={["history"]}>
        <TabList aria-label="Order">
          <Tab id="summary">Summary</Tab>
          <Tab id="payments">Payments</Tab>
          <Tab id="history">History</Tab>
        </TabList>
        <TabPanel id="summary" style={panel}>3 items, shipped.</TabPanel>
        <TabPanel id="payments" style={panel}>Paid by card.</TabPanel>
        <TabPanel id="history" style={panel}>Not available yet.</TabPanel>
      </Tabs>
    </div>
  );
}
```

{% endcode %}

### Many tabs

When the tabs are wider than their container, arrows appear at both ends. Each arrow scrolls the row by 200px. The tabs also scroll with a trackpad or touch, without a visible scrollbar.

{% code title="tabs/overflow\.tsx" %}

```tsx
import { Tab, TabList, TabPanel, Tabs } from "@rierino-open/core-ui";

const months = ["January", "February", "March", "April", "May", "June", "July", "August"];

export default function TabsOverflow() {
  return (
    <div style={{ width: 360 }}>
      <Tabs>
        <TabList aria-label="Month">
          {months.map((month) => (
            <Tab key={month} id={month}>
              {month}
            </Tab>
          ))}
        </TabList>
        {months.map((month) => (
          <TabPanel key={month} id={month} style={{ padding: "16px 4px", fontSize: 13 }}>
            Sales in {month}
          </TabPanel>
        ))}
      </Tabs>
    </div>
  );
}
```

{% endcode %}

The arrows are checked when the tabs first render and when the window is resized, not when tabs are added later.

### Tabs from data

Pass an array as `items` on `TabList` and a function as its child. Render the panels with your own `map`, with matching `id`s.

{% code title="tabs/dynamic.tsx" %}

```tsx
import { Tab, TabList, TabPanel, Tabs } from "@rierino-open/core-ui";

const locales = [
  { id: "en", name: "English", title: "Linen shirt" },
  { id: "tr", name: "Türkçe", title: "Keten gömlek" },
  { id: "de", name: "Deutsch", title: "Leinenhemd" },
];

export default function TabsDynamic() {
  return (
    <div style={{ width: "100%", maxWidth: 560 }}>
      <Tabs>
        <TabList aria-label="Translations" items={locales}>
          {(locale) => <Tab id={locale.id}>{locale.name}</Tab>}
        </TabList>
        {locales.map((locale) => (
          <TabPanel key={locale.id} id={locale.id} style={{ padding: "16px 4px", fontSize: 13 }}>
            Title: {locale.title}
          </TabPanel>
        ))}
      </Tabs>
    </div>
  );
}
```

{% endcode %}

### Manual activation

By default, moving between tabs with the arrow keys also selects them. With `keyboardActivation="manual"`, the arrow keys only move focus, and `Enter` or `Space` selects the focused tab. Use it when showing a panel is slow, such as a report that loads data.

{% code title="tabs/manual.tsx" %}

```tsx
import { Tab, TabList, TabPanel, Tabs } from "@rierino-open/core-ui";

const panel = { padding: "16px 4px", fontSize: 13 };

export default function TabsManual() {
  return (
    <div style={{ width: "100%", maxWidth: 560 }}>
      <Tabs keyboardActivation="manual">
        <TabList aria-label="Reports">
          <Tab id="sales">Sales</Tab>
          <Tab id="returns">Returns</Tab>
          <Tab id="stock">Stock</Tab>
        </TabList>
        <TabPanel id="sales" style={panel}>Sales report</TabPanel>
        <TabPanel id="returns" style={panel}>Returns report</TabPanel>
        <TabPanel id="stock" style={panel}>Stock report</TabPanel>
      </Tabs>
    </div>
  );
}
```

{% endcode %}

## Keyboard

| Key             | Action                                                                    |
| --------------- | ------------------------------------------------------------------------- |
| `Tab`           | Moves into the tab list, onto the selected tab; again, into its panel     |
| `←` `→`         | Moves to the previous or next tab, wrapping around. `↑` `↓` when vertical |
| `Home` `End`    | Moves to the first or last tab                                            |
| `Enter` `Space` | Selects the focused tab, with `keyboardActivation="manual"`               |

## Accessibility

* **Name the tab list** with `aria-label` on `TabList`, such as "Product".
* Each tab is linked to its panel, so screen readers announce which panel a tab controls and name the panel after its tab.
* A panel with nothing focusable inside can itself be focused, so keyboard users can reach its content.

## Styling

Tabs are uppercase, 13px bold text. The selected tab is underlined in `--primary`, and the scroll arrows use `--global-fg-bright`. See [theme variables](https://docs.rierino.com/sdk-core-ui/foundations/colors.md#theme-variables).

| Attribute            | On            | Present when                |
| -------------------- | ------------- | --------------------------- |
| `data-selected`      | Tab           | The tab is selected         |
| `data-hovered`       | Tab           | The pointer is over the tab |
| `data-focus-visible` | Tab           | The tab has keyboard focus  |
| `data-disabled`      | Tab           | The tab is disabled         |
| `data-orientation`   | Tabs, TabList | `horizontal` or `vertical`  |

`className` on `TabList` is applied to both the list and the row around it that holds the scroll arrows.

## API reference

### Tabs

| Prop                 | Type                            | Default        | Description                                                                                                                                                                        |
| -------------------- | ------------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `disabledKeys`       | `Iterable<Key>`                 |                | The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.                                                                            |
| `isDisabled`         | `boolean`                       |                | Whether the TabList is disabled. Shows that a selection exists, but is not available in that circumstance.                                                                         |
| `selectedKey`        | `Key`                           |                | The currently selected key in the collection (controlled).                                                                                                                         |
| `defaultSelectedKey` | `Key`                           |                | The initial selected keys in the collection (uncontrolled).                                                                                                                        |
| `onSelectionChange`  | `((key: Key) => void)`          |                | Handler that is called when the selection changes.                                                                                                                                 |
| `keyboardActivation` | `"automatic" \| "manual"`       | `'automatic'`  | Whether tabs are activated automatically on focus or manually.                                                                                                                     |
| `orientation`        | `Orientation`                   | `'horizontal'` | The orientation of the tabs.                                                                                                                                                       |
| `className`          | `string \| ((state) => string)` |                | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. |

### TabList

| Prop         | Type                                  | Default | Description                                                                                                                                                                        |
| ------------ | ------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `aria-label` | `string`                              |         | Defines a string value that labels the current element.                                                                                                                            |
| `items`      | `Iterable<object>`                    |         | Item objects in the collection.                                                                                                                                                    |
| `className`  | `string \| ((state) => string)`       |         | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. |
| `children`   | `ReactNode \| ((state) => ReactNode)` |         | The contents of the collection.                                                                                                                                                    |

### Tab

| Prop         | Type                                  | Default | Description                                                                                                                                                                        |
| ------------ | ------------------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `className`  | `string \| ((state) => string)`       |         | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state. |
| `children`   | `ReactNode \| ((state) => ReactNode)` |         | The children of the component. A function may be provided to alter the children based on component state.                                                                          |
| `id`         | `Key`                                 |         | The unique id of the tab.                                                                                                                                                          |
| `isDisabled` | `boolean`                             |         | Whether the tab is disabled.                                                                                                                                                       |

### TabPanel

| Prop               | Type                                  | Default | Description                                                                                                                                                                                                             |
| ------------------ | ------------------------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`               | `Key`                                 |         | The unique id of the tab.                                                                                                                                                                                               |
| `className`        | `string \| ((state) => string)`       |         | The CSS [className](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) for the element. A function may be provided to compute the class based on component state.                                      |
| `children`         | `ReactNode \| ((state) => ReactNode)` |         | The children of the component. A function may be provided to alter the children based on component state.                                                                                                               |
| `shouldForceMount` | `boolean`                             | `false` | Whether to mount the tab panel in the DOM even when it is not currently selected. Inactive tab panels are inert and cannot be interacted with. They must be styled appropriately so this is clear to the user visually. |

These also accept the other props of React Aria's [Tabs](https://react-spectrum.adobe.com/react-aria/Tabs.html#props) components.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rierino.com/sdk-core-ui/components/tabs.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
