← Gallery

Tabs

UI primitive
tabs

Switches between views of the same content in place, without leaving the page: Overview / Activity, Week / Month.

Switches between views of the same content in place, without leaving the page: Overview / Activity, Week / Month. Each tab shows a panel; only one panel is visible at a time.

Live examples

Selected, unselected, disabled

Anatomy

  • Tabs — the root that holds the selected value.
  • TabsList — the track that holds the triggers.
  • TabsTrigger — one tab; the selected one sits on a card-coloured surface.
  • TabsContent — the panel for one tab.

From the code

Tokens consumed
cardforegroundmutedmuted-foregroundring
Radius
recipe control radius (ss-pattern-control → --ss-control-radius, 0–999px by brand recipe or the project's recorded corner)
Focus
focus-visible:border-ring · focus-visible:outline-1 · focus-visible:outline-ring · focus-visible:ring-[3px] · focus-visible:ring-ring/50
Motion
transition-[color,box-shadow]

States

StateLooksNote
Selectedcard surface on the muted track.Exactly one at a time.
UnselectedForeground text on the track.—
Focus3px ring in the ring role at 50%.Arrow keys move between tabs (Radix).
Disabled50% opacity, not focusable.Say why elsewhere if the reason is not obvious.

Do

  • Use two to five tabs with short labels.
  • Switch instantly; no slide animation between panels (DESIGN-LANGUAGE §42).
  • Keep each panel about the same kind of content so switching compares like with like.

Don't

  • Don't use tabs for steps in a sequence (use a stepper) or to move between pages (use links).
  • Don't nest tabs inside tabs.
  • Don't hide information the user needs to compare at a glance behind separate tabs; show it side by side.

Known gaps

  • At the :root control height the track is 40px tall, under the 44px touch minimum (DESIGN-LANGUAGE §41); its height follows --ss-control-height.
  • Only the segmented style exists. The token canon sample (research/tokens, component.tab.bd.active) assumes an underline tab with an active border; there is no underline variant yet.
  • For two to four options inside a card header, DESIGN-LANGUAGE §10 asks for a pill toggle; SegmentedControl or ToggleGroup fits that job better than Tabs.

Machine checks

  • Height under the 44px touch minimum (DESIGN-LANGUAGE §41) at the :root control height (40px): tabs-list 40px. On touch surfaces, extend the hit area or use a taller size.

Sources: DESIGN-LANGUAGE §42 Tab & navigation details; §10 Selection UI rules; §41 Touch targets · research/tokens/README.md (token canon sample, #96)

Size
1.9 KB
Exports
4
Imports
3
Type
ui

Exports

TabsTabsListTabsTriggerTabsContent

Imports

  • react
  • @radix-ui/react-tabs
  • ./utils
"use client";

import * as React from "react";
import * as TabsPrimitive from "@radix-ui/react-tabs";

import { cn } from "./utils";

function Tabs({
  className,
  ...props
}: React.ComponentProps<typeof TabsPrimitive.Root>) {
  return (
    <TabsPrimitive.Root
      data-slot="tabs"
      className={cn("flex flex-col gap-2", className)}
      {...props}
    />
  );
}

function TabsList({
  className,
  ...props
}: React.ComponentProps<typeof TabsPrimitive.List>) {
  return (
    <TabsPrimitive.List
      data-slot="tabs-list"
      className={cn(
        "ss-pattern-control bg-muted text-muted-foreground inline-flex h-[var(--ss-control-height,40px)] w-fit items-center justify-center p-[3px] flex",
        className,
      )}
      {...props}
    />
  );
}

function TabsTrigger({
  className,
  ...props
}: React.ComponentProps<typeof TabsPrimitive.Trigger>) {
  return (
    <TabsPrimitive.Trigger
      data-slot="tabs-trigger"
      className={cn(
        "ss-pattern-control data-[state=active]:bg-card dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
        className,
      )}
      {...props}
    />
  );
}

function TabsContent({
  className,
  ...props
}: React.ComponentProps<typeof TabsPrimitive.Content>) {
  return (
    <TabsPrimitive.Content
      data-slot="tabs-content"
      className={cn("flex-1 outline-none", className)}
      {...props}
    />
  );
}

export { Tabs, TabsList, TabsTrigger, TabsContent };