# Tabs

Switch between related panels without leaving the page.

Switch between related panels without leaving the page.

<p className="zenos-base-ui-source">
  Backed by <a href="https://base-ui.com/react/components/tabs">Base UI Tabs</a> for upstream
  behavior and configuration. Zenos owns the public API, styling, and composition shown on this
  page.
</p>

```tsx
import { NewspaperIcon, ShieldPlusIcon } from "@phosphor-icons/react";
import { Badge, Stack, Tabs } from "@zentara-co/zenos-ui";
import { type ReactNode } from "react";

function TabsCountBadge({ children }: { children: ReactNode }) {
  return (
    <Badge
      variant="soft"
      color="neutral"
      className="rounded-lg border-transparent px-1.5 py-0 type-body-s"
    >
      {children}
    </Badge>
  );
}

function TabsPatternsExample() {
  return (
    <Stack gap="4" align="center" className="w-full">
      <Tabs.Root defaultValue="overview">
        <Tabs.List aria-label="Workspace views">
          <Tabs.Tab value="overview">
            <ShieldPlusIcon aria-hidden />
            Overview
            <TabsCountBadge>25</TabsCountBadge>
          </Tabs.Tab>
          <Tabs.Tab value="activity" disabled>
            <ShieldPlusIcon aria-hidden />
            Activity
            <TabsCountBadge>25</TabsCountBadge>
          </Tabs.Tab>
          <Tabs.Tab value="reports">
            <ShieldPlusIcon aria-hidden />
            Reports
            <TabsCountBadge>25</TabsCountBadge>
          </Tabs.Tab>
        </Tabs.List>
        <Tabs.Content value="overview" className="p-3">
          Workspace overview
        </Tabs.Content>
        <Tabs.Content value="reports" className="p-3">
          Workspace reports
        </Tabs.Content>
      </Tabs.Root>

      <Tabs.Root defaultValue="overview">
        <Tabs.List variant="underline" aria-label="Project sections">
          <Tabs.Tab value="overview">
            <NewspaperIcon aria-hidden />
            Overview
            <TabsCountBadge>25</TabsCountBadge>
          </Tabs.Tab>
          <Tabs.Tab value="activity">
            <NewspaperIcon aria-hidden />
            Activity
            <TabsCountBadge>25</TabsCountBadge>
          </Tabs.Tab>
          <Tabs.Tab value="members">
            <NewspaperIcon aria-hidden />
            Members
          </Tabs.Tab>
          <Tabs.Tab value="settings" disabled>
            <NewspaperIcon aria-hidden />
            Settings
          </Tabs.Tab>
        </Tabs.List>
        <Tabs.Content value="overview" className="p-3">
          Project overview
        </Tabs.Content>
        <Tabs.Content value="activity" className="p-3">
          Recent project activity
        </Tabs.Content>
        <Tabs.Content value="members" className="p-3">
          Project members
        </Tabs.Content>
      </Tabs.Root>
    </Stack>
  );
}
```

## Import

```tsx
import { Tabs } from "@zentara-co/zenos-ui";
```

## Variants

`default` renders a connected segmented control with end-cap rounding. `underline` uses a bottom selection indicator and works well for page-level sections. Pair tabs with icons and `Badge` counts; active tabs style nested `[data-slot=badge]` for primary counts. Set the variant on `Tabs.List`; every tab inherits it unless explicitly overridden.

```tsx
import { Stack, Tabs } from "@zentara-co/zenos-ui";

type CatalogVariantProps = { limit?: number };

const limited = <T,>(items: readonly T[], limit?: number) =>
  limit === undefined ? items : items.slice(0, limit);

function TabsVariantsExample({ limit }: CatalogVariantProps = {}) {
  if (limit !== undefined) {
    return (
      <Stack gap="3" align="center" className="w-full">
        {limited(["default", "underline"] as const, limit).map((variant) => (
          <Tabs.Root key={variant} defaultValue="one">
            <Tabs.List variant={variant}>
              <Tabs.Tab value="one">One</Tabs.Tab>
              <Tabs.Tab value="two">Two</Tabs.Tab>
            </Tabs.List>
          </Tabs.Root>
        ))}
      </Stack>
    );
  }

  return (
    <Stack gap="6" className="w-full">
      {(["default", "underline"] as const).map((variant) => (
        <Tabs.Root key={variant} defaultValue="one">
          <Tabs.List variant={variant}>
            <Tabs.Tab value="one">Overview</Tabs.Tab>
            <Tabs.Tab value="two">Activity</Tabs.Tab>
          </Tabs.List>
          <Tabs.Content value="one" className="p-3">
            {variant} tabs
          </Tabs.Content>
          <Tabs.Content value="two" className="p-3">
            Activity
          </Tabs.Content>
        </Tabs.Root>
      ))}
    </Stack>
  );
}
```

Tabs are horizontal. Use `default` for compact view switching and `underline` for broader content sections. If a vertical layout or URL navigation is required, use an appropriate navigation component instead.

## Custom styling

Every Tabs part accepts `className`. Style individual parts directly, or scope a cohesive treatment from `Tabs.List` with stable `data-slot` attributes and Base UI's `data-active` state. Keep selection, disabled state, and other behavior in their dedicated props.

```tsx
import { Tabs } from "@zentara-co/zenos-ui";

function TabsCustomStylingExample() {
  return (
    <Tabs.Root
      defaultValue="summary"
      className="w-full max-w-xl rounded-xl border border-border-accent-teal-default bg-background-accent-teal-subtlest-default p-2"
    >
      <Tabs.List
        aria-label="Project insights"
        className="w-full gap-1 rounded-lg border-0 bg-background-neutral-card p-1 shadow-raised [&_[data-slot=tabs-tab]]:flex-1 [&_[data-slot=tabs-tab]]:rounded-md [&_[data-slot=tabs-tab]]:border-transparent [&_[data-slot=tabs-tab]]:bg-transparent [&_[data-slot=tabs-tab]]:text-text-accent-teal-bolder [&_[data-slot=tabs-tab]]:hover:bg-background-accent-teal-subtlest-hover [&_[data-slot=tabs-tab][data-active]]:bg-background-accent-teal-bolder-default [&_[data-slot=tabs-tab][data-active]]:text-text-contrary"
      >
        <Tabs.Tab value="summary">Summary</Tabs.Tab>
        <Tabs.Tab value="activity">Activity</Tabs.Tab>
        <Tabs.Tab value="members">Members</Tabs.Tab>
      </Tabs.List>
      <Tabs.Content
        value="summary"
        className="rounded-lg bg-background-neutral-card p-4 text-text-accent-teal-bolder"
      >
        Project health, ownership, and delivery status.
      </Tabs.Content>
      <Tabs.Content
        value="activity"
        className="rounded-lg bg-background-neutral-card p-4 text-text-accent-teal-bolder"
      >
        Recent changes across the project workspace.
      </Tabs.Content>
      <Tabs.Content
        value="members"
        className="rounded-lg bg-background-neutral-card p-4 text-text-accent-teal-bolder"
      >
        Members and teams with access to this project.
      </Tabs.Content>
    </Tabs.Root>
  );
}
```

## Controlled and disabled

Use `value` with `onValueChange` when application state owns the active panel. Disabled tabs remain visible but are skipped by pointer and keyboard activation.

```tsx
import { Stack, Tabs, Text } from "@zentara-co/zenos-ui";
import { useState } from "react";

function TabsControlledExample() {
  const [value, setValue] = useState("overview");

  return (
    <Stack gap="3" className="w-full max-w-xl">
      <Tabs.Root value={value} onValueChange={setValue}>
        <Tabs.List variant="underline">
          <Tabs.Tab value="overview">Overview</Tabs.Tab>
          <Tabs.Tab value="activity">Activity</Tabs.Tab>
          <Tabs.Tab value="billing">Billing</Tabs.Tab>
          <Tabs.Tab value="archive" disabled>
            Archive
          </Tabs.Tab>
        </Tabs.List>
        <Tabs.Content value="overview" className="rounded-md border p-4">
          Workspace health and recent security posture.
        </Tabs.Content>
        <Tabs.Content value="activity" className="rounded-md border p-4">
          Recent changes made by workspace members.
        </Tabs.Content>
        <Tabs.Content value="billing" className="rounded-md border p-4">
          Subscription, usage, and invoice information.
        </Tabs.Content>
      </Tabs.Root>
      <Text size="s" color="subtle" aria-live="polite">
        Active tab: {value}
      </Text>
    </Stack>
  );
}
```

## Animated indicator

`Tabs.Indicator` is optional. Place it inside a `default` list when one moving selection surface should sit behind the tabs. The indicator follows the active tab's measured position and disables its transition under reduced motion. The `underline` variant already draws its active marker and does not need this part.

```tsx
import { Tabs } from "@zentara-co/zenos-ui";

function TabsIndicatorExample() {
  return (
    <Tabs.Root defaultValue="details" className="w-full max-w-lg">
      <Tabs.List>
        <Tabs.Tab
          value="details"
          className="data-[active]:border-transparent data-[active]:bg-transparent"
        >
          Details
        </Tabs.Tab>
        <Tabs.Tab
          value="permissions"
          className="data-[active]:border-transparent data-[active]:bg-transparent"
        >
          Permissions
        </Tabs.Tab>
        <Tabs.Tab
          value="history"
          className="data-[active]:border-transparent data-[active]:bg-transparent"
        >
          History
        </Tabs.Tab>
        <Tabs.Indicator />
      </Tabs.List>
      <Tabs.Content value="details" className="p-4">
        Asset ownership and environment details.
      </Tabs.Content>
      <Tabs.Content value="permissions" className="p-4">
        Members and teams with access to this asset.
      </Tabs.Content>
      <Tabs.Content value="history" className="p-4">
        Changes recorded during the last 30 days.
      </Tabs.Content>
    </Tabs.Root>
  );
}
```

## Long tab lists

When all labels remain useful, place the list in a horizontal overflow container rather than compressing or wrapping tabs into multiple lines. For large information architectures, consider navigation instead of an excessively long tab set.

```tsx
import { Tabs } from "@zentara-co/zenos-ui";

function TabsOverflowExample() {
  const items = [
    "Overview",
    "Activity",
    "Assets",
    "Members",
    "Policies",
    "Integrations",
    "Notifications",
    "Billing",
    "Audit log",
    "Advanced",
  ];

  return (
    <Tabs.Root defaultValue="Overview" className="w-full min-w-0">
      <div className="w-full overflow-x-auto">
        <Tabs.List variant="underline" className="min-w-max justify-start">
          {items.map((item) => (
            <Tabs.Tab key={item} value={item}>
              {item}
            </Tabs.Tab>
          ))}
        </Tabs.List>
      </div>
      {items.map((item) => (
        <Tabs.Content key={item} value={item} className="p-4">
          {item} settings
        </Tabs.Content>
      ))}
    </Tabs.Root>
  );
}
```

## Variants

default, underline

## Anatomy

```text
Tabs.Root
Tabs.List
Tabs.Tab
Tabs.Indicator
Tabs.Content
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| Root.value | string | — | Controlled active tab. |
| Root.defaultValue | string | — | Initial uncontrolled tab. |
| Root.onValueChange | (value: string, eventDetails) => void | — | Runs when active tab changes. |
| Root.activationMode | automatic \| manual | automatic | Controls whether focus or explicit activation selects a tab. |
| List.variant | default \| underline | default | Visual treatment inherited by tabs in the list. |
| Tab.disabled | boolean | false | Prevents a tab from receiving activation. |
| Tab.variant | default \| underline | — | Overrides the visual treatment inherited from Tabs.List. |
| native props | React.Base UI Tabs props | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Tabs preserve Base UI's tab, tablist, and tabpanel relationships. Left and Right Arrow move between tabs; Home and End move to the first and last enabled tabs. Enter or Space activates a focused tab when activation is manual. Keep labels short, ensure every tab has a corresponding panel, and do not use Tabs as site navigation.

Source: https://zenos-ui.pages.dev/components/tabs/