# Animated Tabs for UI SDK (/docs/components/tabs)

The key stretches across the list to the tab you pick, and the panel slides in from that side.

<ComponentPreview slug="tabs" source="{&#x22;code&#x22;:&#x22;\&#x22;use client\&#x22;\n\nimport * as React from \&#x22;react\&#x22;\n\nimport { Tabs, TabsList, TabsPanel, TabsPanels, TabsTab } from \&#x22;@/components/keyframery/tabs\&#x22;\n\nconst people = [\n  { initials: \&#x22;CD\&#x22;, name: \&#x22;Clare Dawson\&#x22;, role: \&#x22;Owner\&#x22; },\n  { initials: \&#x22;RF\&#x22;, name: \&#x22;Rob Fenwick\&#x22;, role: \&#x22;Editor\&#x22; },\n  { initials: \&#x22;NH\&#x22;, name: \&#x22;Nadia Haddad\&#x22;, role: \&#x22;Viewer\&#x22; },\n]\n\nfunction Stat({ label, value }: { label: string; value: string }) {\n  return (\n    <div className=\&#x22;rounded-[10px] bg-muted/70 px-3 py-2.5\&#x22;>\n      <div className=\&#x22;text-[11px] font-medium text-muted-foreground\&#x22;>{label}</div>\n      <div className=\&#x22;mt-1 text-[15px] font-semibold tracking-tight tabular-nums\&#x22;>{value}</div>\n    </div>\n  )\n}\n\nexport default function TabsDemo({\n  orientation = \&#x22;horizontal\&#x22;,\n  activation = \&#x22;automatic\&#x22;,\n  loop = true,\n  disabled = false,\n  hiddenUntilFound = false,\n  keepMounted = false,\n  defaultTab = \&#x22;overview\&#x22;,\n  items = 4,\n  peopleCount = 3,\n  title = \&#x22;Summer fête\&#x22;,\n  description = \&#x22;Saturday 12 July, on the village green\&#x22;,\n  width = 420,\n  height = 32,\n  radius = 12,\n  keyRadius = 9,\n  gap = 2,\n  track = \&#x22;\&#x22;,\n  keyFill = \&#x22;\&#x22;,\n  ink = \&#x22;\&#x22;,\n  selectedInk = \&#x22;\&#x22;,\n}: {\n  orientation?: \&#x22;horizontal\&#x22; | \&#x22;vertical\&#x22;\n  activation?: \&#x22;automatic\&#x22; | \&#x22;manual\&#x22;\n  loop?: boolean\n  disabled?: boolean\n  hiddenUntilFound?: boolean\n  keepMounted?: boolean\n  defaultTab?: \&#x22;overview\&#x22; | \&#x22;activity\&#x22; | \&#x22;people\&#x22; | \&#x22;billing\&#x22;\n  items?: number\n  peopleCount?: number\n  title?: string\n  description?: string\n  width?: number\n  height?: number\n  radius?: number\n  keyRadius?: number\n  gap?: number\n  track?: string\n  keyFill?: string\n  ink?: string\n  selectedInk?: string\n} = {}) {\n  const theme = {\n    \&#x22;--tabs-height\&#x22;: `${height}px`,\n    \&#x22;--tabs-radius\&#x22;: `${radius}px`,\n    \&#x22;--tabs-key-radius\&#x22;: `${keyRadius}px`,\n    \&#x22;--tabs-gap\&#x22;: `${gap}px`,\n    ...(track ? { \&#x22;--tabs-track\&#x22;: track } : {}),\n    ...(keyFill ? { \&#x22;--tabs-key\&#x22;: keyFill } : {}),\n    ...(ink ? { \&#x22;--tabs-ink\&#x22;: ink } : {}),\n    ...(selectedInk ? { \&#x22;--tabs-selected-ink\&#x22;: selectedInk } : {}),\n  } as React.CSSProperties\n  return (\n    <Tabs key={defaultTab} defaultValue={[\&#x22;overview\&#x22;, \&#x22;activity\&#x22;, \&#x22;people\&#x22;, \&#x22;billing\&#x22;].slice(0, items).includes(defaultTab) ? defaultTab : \&#x22;overview\&#x22;} orientation={orientation} activation={activation} loop={loop} hiddenUntilFound={hiddenUntilFound} style={{ ...theme, maxWidth: width }} className=\&#x22;w-full\&#x22;>\n      <TabsList aria-label=\&#x22;Event\&#x22;>\n        {[[\&#x22;overview\&#x22;, \&#x22;Overview\&#x22;], [\&#x22;activity\&#x22;, \&#x22;Activity\&#x22;], [\&#x22;people\&#x22;, \&#x22;People\&#x22;], [\&#x22;billing\&#x22;, \&#x22;Money\&#x22;]].slice(0, items).map(([value, label]) => <TabsTab key={value} value={value} disabled={disabled}>{label}</TabsTab>)}\n      </TabsList>\n      <TabsPanels className=\&#x22;h-[168px]\&#x22;>\n        <TabsPanel keepMounted={keepMounted} value=\&#x22;overview\&#x22;>\n          <h3 className=\&#x22;text-[15px] font-semibold tracking-tight\&#x22;>{title}</h3>\n          <p className=\&#x22;mt-1 text-[13px] text-muted-foreground\&#x22;>{description}</p>\n          <div className=\&#x22;mt-4 grid grid-cols-3 gap-2\&#x22;>\n            <Stat label=\&#x22;Stalls\&#x22; value=\&#x22;14 of 20\&#x22; />\n            <Stat label=\&#x22;Raised\&#x22; value=\&#x22;£1,240\&#x22; />\n            <Stat label=\&#x22;Days left\&#x22; value=\&#x22;23\&#x22; />\n          </div>\n        </TabsPanel>\n        <TabsPanel keepMounted={keepMounted} value=\&#x22;activity\&#x22;>\n          <ul className=\&#x22;space-y-3 text-[13px]\&#x22;>\n            <li className=\&#x22;flex items-baseline justify-between gap-4\&#x22;>\n              <span><b className=\&#x22;font-medium\&#x22;>Clare</b> booked the brass band</span>\n              <span className=\&#x22;text-muted-foreground tabular-nums\&#x22;>2h</span>\n            </li>\n            <li className=\&#x22;flex items-baseline justify-between gap-4\&#x22;>\n              <span><b className=\&#x22;font-medium\&#x22;>Rob</b> added 3 cake stalls</span>\n              <span className=\&#x22;text-muted-foreground tabular-nums\&#x22;>5h</span>\n            </li>\n            <li className=\&#x22;flex items-baseline justify-between gap-4\&#x22;>\n              <span><b className=\&#x22;font-medium\&#x22;>Nadia</b> left a note on parking</span>\n              <span className=\&#x22;text-muted-foreground tabular-nums\&#x22;>1d</span>\n            </li>\n            <li className=\&#x22;flex items-baseline justify-between gap-4\&#x22;>\n              <span><b className=\&#x22;font-medium\&#x22;>Clare</b> set the target to £2,000</span>\n              <span className=\&#x22;text-muted-foreground tabular-nums\&#x22;>3d</span>\n            </li>\n          </ul>\n        </TabsPanel>\n        <TabsPanel keepMounted={keepMounted} value=\&#x22;people\&#x22;>\n          <ul className=\&#x22;space-y-2.5\&#x22;>\n            {people.slice(0, peopleCount).map((p) => (\n              <li key={p.initials} className=\&#x22;flex items-center gap-3 text-[13px]\&#x22;>\n                <span className=\&#x22;grid size-8 place-items-center rounded-full bg-muted text-[11px] font-semibold text-muted-foreground\&#x22;>\n                  {p.initials}\n                </span>\n                <span className=\&#x22;font-medium\&#x22;>{p.name}</span>\n                <span className=\&#x22;ml-auto text-muted-foreground\&#x22;>{p.role}</span>\n              </li>\n            ))}\n          </ul>\n        </TabsPanel>\n        <TabsPanel keepMounted={keepMounted} value=\&#x22;billing\&#x22;>\n          <h3 className=\&#x22;text-[15px] font-semibold tracking-tight\&#x22;>Takings so far</h3>\n          <p className=\&#x22;mt-1 text-[13px] text-muted-foreground\&#x22;>Card reader rented until 6pm</p>\n          <div className=\&#x22;mt-4 grid grid-cols-2 gap-2\&#x22;>\n            <Stat label=\&#x22;Cash\&#x22; value=\&#x22;£860\&#x22; />\n            <Stat label=\&#x22;Card\&#x22; value=\&#x22;£380\&#x22; />\n          </div>\n        </TabsPanel>\n      </TabsPanels>\n    </Tabs>\n  )\n}&#x22;,&#x22;bindings&#x22;:{&#x22;orientation&#x22;:[727,739],&#x22;activation&#x22;:[756,767],&#x22;loop&#x22;:[778,782],&#x22;disabled&#x22;:[797,802],&#x22;hiddenUntilFound&#x22;:[825,830],&#x22;keepMounted&#x22;:[848,853],&#x22;defaultTab&#x22;:[870,880],&#x22;items&#x22;:[892,893],&#x22;peopleCount&#x22;:[911,912],&#x22;title&#x22;:[924,937],&#x22;description&#x22;:[955,995],&#x22;width&#x22;:[1007,1010],&#x22;height&#x22;:[1023,1025],&#x22;radius&#x22;:[1038,1040],&#x22;keyRadius&#x22;:[1056,1057],&#x22;gap&#x22;:[1067,1068],&#x22;track&#x22;:[1080,1082],&#x22;keyFill&#x22;:[1096,1098],&#x22;ink&#x22;:[1108,1110],&#x22;selectedInk&#x22;:[1128,1130]},&#x22;root&#x22;:[2033,5402],&#x22;importOffset&#x22;:139}" />

## Installation [#installation]

**CLI**

```bash
npx shadcn@latest add @keyframery/tabs
```

This adds `components/keyframery/tabs.tsx` and its primitive to your project, and installs UI SDK. The motion tokens are added to your global CSS the first time you install a component.

**Manual**

**Install the dependencies**

```bash
npm install @ui-sdk/core@0.1.0-beta.9 @ui-sdk/react@0.1.0-beta.9 clsx tailwind-merge
```

**Add the motion tokens**

Copy the [motion tokens](/docs/installation#what-the-cli-adds-to-your-css) into your global CSS, and this file into `lib/keyframery.tsx`. Every component shares them.

**lib/keyframery.tsx**

```tsx
"use client"

/* Speed for Keyframery components, as a prop.

   Every duration in the components is written as calc(Nms * var(--kf-speed, 1)). These helpers set
   that variable for you, so nobody has to know it exists:

     <Tabs speed="fast">                      one component
     <KeyframeryProvider speed="slow">        the whole app

   Parts that render in a portal (popups, menus, dialogs) are not inside the component in the page,
   so they pick the speed up through React context instead of the CSS cascade. */

import * as React from "react"

/** `"fast"` (0.6×), `"normal"` (1×), `"slow"` (1.4×), or any multiplier: `0.8` is 20% quicker. */
export type Speed = "fast" | "normal" | "slow" | number

export type SpeedProps = {
  /** How fast the component moves. `"fast"` (0.6×), `"normal"` (1×), `"slow"` (1.4×), or a multiplier like `0.8`. Popups follow it too. */
  speed?: Speed
}

export type MotionStyleName = "springy" | "calm" | "snappy" | "playful"

const presets = { fast: 0.6, normal: 1, slow: 1.4 } as const

export function speedValue(speed: Speed | undefined): number | undefined {
  if (speed === undefined) return undefined
  return typeof speed === "number" ? speed : presets[speed]
}

const SpeedContext = React.createContext<number | undefined>(undefined)

type SpeedStyle = React.CSSProperties & { "--kf-speed"?: number }

/* Wraps a component's parts. Without `speed` it adds nothing to the page. With it, a
   `display: contents` element carries the variable to the parts in place, and context carries it
   to the parts in a portal. */
export function Speed({ speed, children }: SpeedProps & { children?: React.ReactNode }) {
  const value = speedValue(speed)
  if (value === undefined) return children
  const style: SpeedStyle = { display: "contents", "--kf-speed": value }
  return (
    <SpeedContext value={value}>
      <span data-slot="speed" style={style}>
        {children}
      </span>
    </SpeedContext>
  )
}

/* For parts that render in a portal: adds the speed of the component they belong to. `style` can
   be an object or UI SDK's function of the part's state. */
export function useSpeedStyle<S>(style: S): S {
  return withSpeed(style, React.useContext(SpeedContext))
}

/* Adds a speed to a part's own `style`, for a part that takes `speed` and renders in a portal. */
export function withSpeed<S>(style: S, speed: Speed | undefined): S {
  const value = speedValue(speed)
  if (value === undefined) return style
  if (typeof style === "function")
    return ((state: unknown) => ({ "--kf-speed": value, ...(style as (s: unknown) => React.CSSProperties)(state) })) as S
  return { "--kf-speed": value, ...(style as React.CSSProperties | undefined) } as S
}

/* UI SDK parts take `children` as content or as a function of the part's state. A styled part
   that adds elements of its own (a chevron, a moving key) wraps either form with this, so the
   function form keeps working. */
export function mapChildren<State>(
  children: React.ReactNode | ((state: State) => React.ReactNode),
  wrap: (content: React.ReactNode) => React.ReactNode,
): React.ReactNode | ((state: State) => React.ReactNode) {
  return typeof children === "function" ? (state: State) => wrap(children(state)) : wrap(children)
}

/* Sets speed and motion style for the whole app, popups included. A component's own `speed` prop
   still wins inside that component. Server-rendered pages can put `data-motion` on <html> directly
   to avoid a change after hydration. */
export function KeyframeryProvider({
  speed,
  motion,
  children,
}: SpeedProps & {
  /** The motion style for the whole app: `"springy"` (the default), `"calm"`, `"snappy"` or `"playful"`. */
  motion?: MotionStyleName
  children?: React.ReactNode
}) {
  const value = speedValue(speed)
  React.useLayoutEffect(() => {
    const html = document.documentElement
    if (motion) html.setAttribute("data-motion", motion)
    if (value !== undefined) html.style.setProperty("--kf-speed", String(value))
    return () => {
      if (motion) html.removeAttribute("data-motion")
      if (value !== undefined) html.style.removeProperty("--kf-speed")
    }
  }, [motion, value])
  return children
}
```

**Copy the component**

**components/keyframery/tabs.tsx**

```tsx
"use client"

export * from "@/components/keyframery/primitives/tabs"

/* Styled tabs: the animated primitive plus the Keyframery look. */

/* Theming: inherit these optional variables; unset values retain the original light/dark tokens.
   --tabs-track: Tab list well (default: --muted).
   --tabs-key: Selected tab surface (default: --background; --accent in dark).
   --tabs-ink: Unselected labels (default: --muted-foreground).
   --tabs-selected-ink: Selected labels (default: --foreground).
   --tabs-height: Tab height (default: 2rem).
   --tabs-radius: List corners (default: 12px).
   --tabs-key-radius: Tab key corners (default: 9px).
   --tabs-gap: Space between tabs (default: 0.125rem).
 */

import * as React from "react"

import {
  Tabs as TabsRoot,
  TabsIndicator as TabsIndicatorPrimitive,
  TabsList as TabsListPrimitive,
  TabsPanel as TabsPanelPrimitive,
  TabsPanels as TabsPanelsPrimitive,
  TabsTab as TabsTabPrimitive,
  TabsTabIcon as TabsTabIconPrimitive,
} from "@/components/keyframery/primitives/tabs"
import { mapChildren, Speed, type SpeedProps } from "@/lib/keyframery"
import { cn } from "@/lib/utils"

/* UI SDK accepts a class name or a function of state; keep both working. */
function withClass<S>(base: string, className: string | ((state: S) => string | undefined) | undefined) {
  return typeof className === "function" ? (state: S) => cn(base, className(state)) : cn(base, className)
}

/* One box shared by the real tab and its copy inside the key, so both lay out identically. */
const tabBox =
  "inline-flex h-[var(--tabs-height,2rem)] shrink-0 items-center justify-center gap-1.5 rounded-[var(--tabs-key-radius,9px)] px-3 text-[13px] leading-none font-medium whitespace-nowrap [&_svg]:size-3.5 [&_svg]:shrink-0"

const listLayout =
  "flex items-center gap-[var(--tabs-gap,0.125rem)] p-1 data-[orientation=vertical]:flex-col data-[orientation=vertical]:items-stretch"

function Tabs({ speed, className, ...props }: React.ComponentProps<typeof TabsRoot> & SpeedProps) {
  return (
    <Speed speed={speed}>
      <TabsRoot
        className={withClass("flex flex-col data-[orientation=vertical]:flex-row data-[orientation=vertical]:gap-4", className)}
        {...props}
      />
    </Speed>
  )
}

function TabsList({
  className,
  children,
  ...props
}: React.ComponentProps<typeof TabsListPrimitive>) {
  return (
    <TabsListPrimitive
      className={withClass(
        cn(
          listLayout,
          "w-fit rounded-[var(--tabs-radius,12px)] bg-[var(--tabs-track,var(--muted))]",
          "shadow-[inset_0_1px_2px_rgb(0_0_0/0.07),inset_0_0_0_1px_rgb(0_0_0/0.035)]",
          "dark:shadow-[inset_0_1px_2px_rgb(0_0_0/0.5),inset_0_0_0_1px_rgb(255_255_255/0.04)]",
        ),
        className,
      )}
      {...props}
    >
      {mapChildren(children, (content) => (
        <>
          {content}
          {/* The key: a raised surface that stretches toward the tab you pick. */}
          <TabsIndicator>
            {/* A copy of the labels in the selected colour, clipped to the key. It is offset by the
                key's own moving edges, so it stays still while the key passes over it. */}
            <span className="absolute inset-0 overflow-hidden rounded-[inherit]">
              <span
                className={cn(
                  listLayout,
                  "absolute text-[color:var(--tabs-selected-ink,var(--foreground))]",
                  "group-data-[orientation=vertical]/key:flex-col group-data-[orientation=vertical]/key:items-stretch",
                  "top-[calc(min(var(--kf-ta),var(--kf-tb))*-1)] left-[calc(min(var(--kf-la),var(--kf-lb))*-1)]",
                  "h-[calc(var(--active-tab-top,0px)+var(--active-tab-height,0px)+var(--active-tab-bottom,0px))]",
                  "w-[calc(var(--active-tab-left,0px)+var(--active-tab-width,0px)+var(--active-tab-right,0px))]",
                )}
              >
                {React.Children.map(content, (child) =>
                  React.isValidElement<{ children?: React.ReactNode }>(child) ? (
                    <span className={tabBox}>{child.props.children}</span>
                  ) : null,
                )}
              </span>
            </span>
          </TabsIndicator>
        </>
      ))}
    </TabsListPrimitive>
  )
}

/* The key on its own. TabsList already renders one, so add this only to a list you build from the
   primitive parts yourself. */
function TabsIndicator({ className, ...props }: React.ComponentProps<typeof TabsIndicatorPrimitive>) {
  return (
    <TabsIndicatorPrimitive
      aria-hidden
      className={withClass(
        cn(
          "group/key z-10 rounded-[var(--tabs-key-radius,9px)] bg-[var(--tabs-key,var(--background))]",
          "shadow-[0_0_0_1px_rgb(0_0_0/0.06),0_1px_1px_rgb(0_0_0/0.05),0_3px_6px_-2px_rgb(0_0_0/0.1)]",
          "dark:bg-[var(--tabs-key,var(--accent))] dark:shadow-[0_0_0_1px_rgb(255_255_255/0.07),inset_0_1px_0_rgb(255_255_255/0.08),0_2px_6px_-1px_rgb(0_0_0/0.6)]",
        ),
        className,
      )}
      {...props}
    />
  )
}

function TabsTab({ className, ...props }: React.ComponentProps<typeof TabsTabPrimitive>) {
  return (
    <TabsTabPrimitive
      className={withClass(
        cn(
          tabBox,
          "relative cursor-pointer text-[color:var(--tabs-ink,var(--muted-foreground))] outline-none select-none",
          "transition-[color,background-color,scale] motion-reduce:transition-none! hover:bg-[color-mix(in_oklab,var(--tabs-selected-ink,var(--foreground))_4.5%,transparent)] hover:text-[color:var(--tabs-selected-ink,var(--foreground))]",
          "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-muted",
          "data-disabled:pointer-events-none data-disabled:opacity-40",
        ),
        className,
      )}
      {...props}
    />
  )
}

/* An icon inside a tab. A tab with only an icon needs an `aria-label`. */
function TabsTabIcon({ className, ...props }: React.ComponentProps<typeof TabsTabIconPrimitive>) {
  return <TabsTabIconPrimitive className={withClass("inline-flex shrink-0 items-center justify-center [&_svg]:size-3.5", className)} {...props} />
}

function TabsPanels({ className, ...props }: React.ComponentProps<typeof TabsPanelsPrimitive>) {
  return <TabsPanelsPrimitive className={cn("mt-3 flex-1", className)} {...props} />
}

function TabsPanel({ className, ...props }: React.ComponentProps<typeof TabsPanelPrimitive>) {
  return (
    <TabsPanelPrimitive
      className={withClass(
        cn(
          "min-w-0 outline-none",
          "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
        ),
        className,
      )}
      {...props}
    />
  )
}

export { Tabs, TabsIndicator, TabsList, TabsPanel, TabsPanels, TabsTab, TabsTabIcon }

/* UI SDK's helpers for this component, passed through. */
export { createTabsController } from "@/components/keyframery/primitives/tabs"
```

**components/keyframery/primitives/tabs.tsx**

```tsx
"use client"

/* Animated drop-in for `@ui-sdk/react/tabs`: same parts, same props. Swap the import and keep your code.
   This file adds motion only. Colours, radii, shadows and spacing stay yours. */

import {
  TabsIndicator as TabsIndicatorPart,
  TabsList as TabsListPart,
  TabsPanel as TabsPanelPart,
  TabsTab as TabsTabPart,
} from "@ui-sdk/react/tabs"
import * as React from "react"

import { cn } from "@/lib/utils"

/* UI SDK accepts a class name or a function of state; keep both working. */
function withClass<S>(base: string, className: string | ((state: S) => string | undefined) | undefined) {
  return typeof className === "function" ? (state: S) => cn(base, className(state)) : cn(base, className)
}

export * from "@ui-sdk/react/tabs"

function TabsList({ className, ...props }: React.ComponentProps<typeof TabsListPart>) {
  return <TabsListPart className={withClass("relative isolate", className)} {...props} />
}

function TabsTab({ className, ...props }: React.ComponentProps<typeof TabsTabPart>) {
  return (
    <TabsTabPart
      className={withClass("transition-[scale] duration-[calc(150ms*var(--kf-speed,1))] ease-spring active:scale-[0.96] motion-reduce:transition-none!", className)}
      {...props}
    />
  )
}

/* Stretch: every edge of the marker is tracked twice, once quickly and once slowly with a
   70ms lag. Each edge then uses whichever of the two is further out, so the edge facing the
   direction of travel leads and the opposite edge follows: the marker stretches toward where
   it is going, then closes up. (No spring here: an overshoot would push it out of its track.) It needs no direction attribute, so it is right on the
   first move and in both directions. The registered properties are inherited, so anything
   inside the indicator can read the same moving edges. */
const stretchProperties = ["la", "lb", "ra", "rb", "ta", "tb", "ba", "bb"]
  .map((n) => `@property --kf-${n}{syntax:"<length>";inherits:true;initial-value:0px}`)
  .join("")

function TabsIndicator({ className, ...props }: React.ComponentProps<typeof TabsIndicatorPart>) {
  /* Hold the transitions until UI SDK has measured the first tab, so the marker
     is simply there on load instead of sliding in from the corner. */
  const [ready, setReady] = React.useState(false)
  React.useEffect(() => {
    const timer = setTimeout(() => setReady(true), 150)
    return () => clearTimeout(timer)
  }, [])

  return (
    <>
      <style href="kf-stretch" precedence="default">
        {stretchProperties}
      </style>
      <TabsIndicatorPart
        data-ready={ready || undefined}
        className={withClass(
          cn(
            "pointer-events-none absolute",
            "[--kf-la:var(--active-tab-left,0px)] [--kf-lb:var(--active-tab-left,0px)] [--kf-ra:var(--active-tab-right,0px)] [--kf-rb:var(--active-tab-right,0px)]",
            "[--kf-ba:var(--active-tab-bottom,0px)] [--kf-bb:var(--active-tab-bottom,0px)] [--kf-ta:var(--active-tab-top,0px)] [--kf-tb:var(--active-tab-top,0px)]",
            "top-[min(var(--kf-ta),var(--kf-tb))] right-[min(var(--kf-ra),var(--kf-rb))] bottom-[min(var(--kf-ba),var(--kf-bb))] left-[min(var(--kf-la),var(--kf-lb))]",
            "motion-reduce:transition-none! data-ready:[transition:--kf-la_calc(260ms*var(--kf-speed,1))_var(--ease-house),--kf-ra_calc(260ms*var(--kf-speed,1))_var(--ease-house),--kf-ta_calc(260ms*var(--kf-speed,1))_var(--ease-house),--kf-ba_calc(260ms*var(--kf-speed,1))_var(--ease-house),--kf-lb_calc(380ms*var(--kf-speed,1))_var(--ease-house)_calc(80ms*var(--kf-speed,1)),--kf-rb_calc(380ms*var(--kf-speed,1))_var(--ease-house)_calc(80ms*var(--kf-speed,1)),--kf-tb_calc(380ms*var(--kf-speed,1))_var(--ease-house)_calc(80ms*var(--kf-speed,1)),--kf-bb_calc(380ms*var(--kf-speed,1))_var(--ease-house)_calc(80ms*var(--kf-speed,1))]",
            "motion-reduce:[transition:none]!",
          ),
          className,
        )}
        {...props}
      />
    </>
  )
}

/* Optional: put the panels inside TabsPanels and the one leaving overlaps the one
   arriving. Without it, the old panel leaves at once and the new one still animates in. */
function TabsPanels({ className, ...props }: React.ComponentProps<"div">) {
  return <div data-slot="tabs-panels" className={cn("group/panels grid min-w-0", className)} {...props} />
}

function TabsPanel({ className, ...props }: React.ComponentProps<typeof TabsPanelPart>) {
  return (
    <TabsPanelPart
      className={withClass(
        cn(
          "transition-[opacity,translate,filter] duration-[calc(460ms*var(--kf-speed,1))] ease-spring",
          "data-starting-style:opacity-0 data-starting-style:blur-[6px]",
          "data-[activation-direction=right]:data-starting-style:translate-x-8 data-[activation-direction=left]:data-starting-style:-translate-x-8",
          "data-[activation-direction=down]:data-starting-style:translate-y-6 data-[activation-direction=up]:data-starting-style:-translate-y-6",
          "data-ending-style:hidden",
          "group-data-[slot=tabs-panels]/panels:[grid-area:1/1] group-data-[slot=tabs-panels]/panels:data-ending-style:block",
          "data-ending-style:opacity-0 data-ending-style:blur-[6px] data-ending-style:duration-[calc(200ms*var(--kf-speed,1))] data-ending-style:ease-house",
          "data-[activation-direction=right]:data-ending-style:-translate-x-6 data-[activation-direction=left]:data-ending-style:translate-x-6",
          "data-[activation-direction=down]:data-ending-style:-translate-y-4 data-[activation-direction=up]:data-ending-style:translate-y-4",
          "motion-reduce:transition-none!",
        ),
        className,
      )}
      {...props}
    />
  )
}

export { TabsIndicator, TabsList, TabsPanel, TabsPanels, TabsTab }
```

**Check the import paths**

The files import from `@/components/keyframery/…` and `@/lib/…`. Change those if your project's aliases differ.

## Usage [#usage]

```tsx
import { Tabs, TabsList, TabsPanel, TabsPanels, TabsTab } from "@/components/keyframery/tabs"

export default function Usage() {
  return (
    <Tabs defaultValue="account">
      <TabsList aria-label="Settings">
        <TabsTab value="account">Account</TabsTab>
        <TabsTab value="password">Password</TabsTab>
      </TabsList>
      <TabsPanels>
        <TabsPanel value="account">Account settings</TabsPanel>
        <TabsPanel value="password">Password settings</TabsPanel>
      </TabsPanels>
    </Tabs>
  )
}
```

### Anatomy [#anatomy]

How the parts fit together:

```text
Tabs
├── TabsList
│   └── TabsTab
└── TabsPanels
    └── TabsPanel
```

## Examples [#examples]

### Basic [#basic]

The key glides to the chosen tab, and the panels slide in from the side you moved towards.

<ExamplePreview name="tabs/basic">
  ```tsx
  import { Tabs, TabsList, TabsPanel, TabsPanels, TabsTab } from "@/components/keyframery/tabs"

  export default function TabsBasic() {
    return (
      <Tabs defaultValue="overview" className="w-full max-w-[380px]">
        <TabsList aria-label="Project">
          <TabsTab value="overview">Overview</TabsTab>
          <TabsTab value="activity">Activity</TabsTab>
          <TabsTab value="settings">Settings</TabsTab>
        </TabsList>
        <TabsPanels className="h-[90px] text-[13px] text-muted-foreground">
          <TabsPanel value="overview">12 open tasks, 3 due this week.</TabsPanel>
          <TabsPanel value="activity">Maya closed “Fix the login page” 2 hours ago.</TabsPanel>
          <TabsPanel value="settings">Rename the project or archive it.</TabsPanel>
        </TabsPanels>
      </Tabs>
    )
  }
  ```
</ExamplePreview>

### Controlled [#controlled]

Pass `value` and `onValueChange`, for example to keep the tab in the URL.

<ExamplePreview name="tabs/controlled">
  ```tsx
  import * as React from "react"

  import { Button } from "@/components/keyframery/button"
  import { Tabs, TabsList, TabsPanel, TabsPanels, TabsTab } from "@/components/keyframery/tabs"

  export default function TabsControlled() {
    const [tab, setTab] = React.useState("details")
    return (
      <Tabs value={tab} onValueChange={(v) => setTab(v ?? "details")} className="w-full max-w-[380px]">
        <TabsList aria-label="Checkout">
          <TabsTab value="details">Details</TabsTab>
          <TabsTab value="payment">Payment</TabsTab>
        </TabsList>
        <TabsPanels className="h-[90px] pt-1">
          <TabsPanel value="details">
            <Button size="sm" variant="primary" onClick={() => setTab("payment")}>
              Continue to payment
            </Button>
          </TabsPanel>
          <TabsPanel value="payment" className="text-[13px] text-muted-foreground">
            Card details go here.
          </TabsPanel>
        </TabsPanels>
      </Tabs>
    )
  }
  ```
</ExamplePreview>

### Vertical [#vertical]

`orientation="vertical"` lists the tabs down the side. Up and down arrows move between them.

<ExamplePreview name="tabs/vertical">
  ```tsx
  import { Tabs, TabsList, TabsPanel, TabsPanels, TabsTab } from "@/components/keyframery/tabs"

  export default function TabsVertical() {
    return (
      <Tabs defaultValue="general" orientation="vertical" className="flex w-full max-w-[420px] flex-row gap-4">
        <TabsList aria-label="Settings">
          <TabsTab value="general">General</TabsTab>
          <TabsTab value="members">Members</TabsTab>
          <TabsTab value="billing">Billing</TabsTab>
        </TabsList>
        <TabsPanels className="flex-1 text-[13px] text-muted-foreground">
          <TabsPanel value="general">Name, logo and time zone.</TabsPanel>
          <TabsPanel value="members">Invite people and set roles.</TabsPanel>
          <TabsPanel value="billing">Plan, cards and invoices.</TabsPanel>
        </TabsPanels>
      </Tabs>
    )
  }
  ```
</ExamplePreview>

### Icons [#icons]

`TabsTabIcon` holds an icon inside a tab. Screen readers skip it, so a tab with only an icon needs an `aria-label`.

<ExamplePreview name="tabs/icons">
  ```tsx
  import { CalendarDays, List, MapPin } from "lucide-react"

  import { Tabs, TabsList, TabsPanel, TabsPanels, TabsTab, TabsTabIcon } from "@/components/keyframery/tabs"

  export default function TabsIcons() {
    return (
      <Tabs defaultValue="list" className="w-full max-w-[340px]">
        <TabsList aria-label="View">
          <TabsTab value="list">
            <TabsTabIcon>
              <List />
            </TabsTabIcon>
            List
          </TabsTab>
          <TabsTab value="map">
            <TabsTabIcon>
              <MapPin />
            </TabsTabIcon>
            Map
          </TabsTab>
          <TabsTab value="dates">
            <TabsTabIcon>
              <CalendarDays />
            </TabsTabIcon>
            Dates
          </TabsTab>
        </TabsList>
        <TabsPanels>
          <TabsPanel value="list" className="text-[13.5px] text-muted-foreground">Every walk, nearest first.</TabsPanel>
          <TabsPanel value="map" className="text-[13.5px] text-muted-foreground">The same walks on a map.</TabsPanel>
          <TabsPanel value="dates" className="text-[13.5px] text-muted-foreground">Walks by the day you planned them.</TabsPanel>
        </TabsPanels>
      </Tabs>
    )
  }
  ```
</ExamplePreview>

## Motion [#motion]

| Move          | What you see                                                               |
| ------------- | -------------------------------------------------------------------------- |
| **Stretch**   | The key stretches across the list toward the tab you pick, then closes up. |
| **Fade**      | Label colours flip exactly at the key's edge as it passes.                 |
| **Direction** | The panel slides in from the side you moved to.                            |

Timing and springiness follow the [motion style](/docs/motion-styles) you set. To change how fast this tabs moves, pass `speed`:

```tsx
<Tabs speed="fast">
  …
</Tabs>
```

`"fast"` is 0.6×, `"slow"` 1.4×, and a number sets the multiplier. With reduced motion turned on, nothing moves: changes happen at once or with a short fade.

## Theming [#theming]

Set these CSS variables on the component or a parent. Leave them unset to follow the light and dark theme. The open Customize panel below the preview lets you try these settings.

| Variable              | What it changes      | Default                        |
| --------------------- | -------------------- | ------------------------------ |
| `--tabs-track`        | Tab list well        | --muted                        |
| `--tabs-key`          | Selected tab surface | --background; --accent in dark |
| `--tabs-ink`          | Unselected labels    | --muted-foreground             |
| `--tabs-selected-ink` | Selected labels      | --foreground                   |
| `--tabs-height`       | Tab height           | 2rem                           |
| `--tabs-radius`       | List corners         | 12px                           |
| `--tabs-key-radius`   | Tab key corners      | 9px                            |
| `--tabs-gap`          | Space between tabs   | 0.125rem                       |

## API reference [#api-reference]

Every part takes `className` and `children`. Parts from UI SDK also take `render`, to draw your own element, and a function of their state for `className` and `style`. Props not listed here are in the [UI SDK tabs reference](https://ui-sdk.dev/docs/components/tabs).

### Tabs [#tabs]

Renders a `<div>`, and takes its props too.

<PropsTable rows="[{&#x22;name&#x22;:&#x22;speed&#x22;,&#x22;type&#x22;:&#x22;\&#x22;fast\&#x22; | \&#x22;normal\&#x22; | \&#x22;slow\&#x22; | number&#x22;,&#x22;default&#x22;:null,&#x22;description&#x22;:&#x22;How fast the component moves. `\&#x22;fast\&#x22;` (0.6×), `\&#x22;normal\&#x22;` (1×), `\&#x22;slow\&#x22;` (1.4×), or a multiplier like `0.8`. Popups follow it too.&#x22;,&#x22;required&#x22;:false},{&#x22;name&#x22;:&#x22;value&#x22;,&#x22;type&#x22;:&#x22;string&#x22;,&#x22;full&#x22;:&#x22;string&#x22;,&#x22;default&#x22;:null,&#x22;description&#x22;:&#x22;The selected tab's value. Pass it to control the tabs.&#x22;,&#x22;required&#x22;:false},{&#x22;name&#x22;:&#x22;defaultValue&#x22;,&#x22;type&#x22;:&#x22;string&#x22;,&#x22;full&#x22;:&#x22;string&#x22;,&#x22;default&#x22;:null,&#x22;description&#x22;:&#x22;Initially selected tab.&#x22;,&#x22;required&#x22;:false},{&#x22;name&#x22;:&#x22;onValueChange&#x22;,&#x22;type&#x22;:&#x22;function&#x22;,&#x22;full&#x22;:&#x22;(value: string | null, details: { reason: \&#x22;find-in-page\&#x22;; event?: Event; source: ChangeSource; cancel: () => void; readonly canceled: boolean; } | { reason: \&#x22;imperative\&#x22;; event?: undefined; source: ChangeSource; cancel: () => void; readonly canceled: boolean; } | { reason: \&#x22;item-press\&#x22;; event?: MouseEvent | KeyboardEvent; source: ChangeSource; cancel: () => void; readonly canceled: boolean; } | { reason: \&#x22;list-navigation\&#x22;; event?: KeyboardEvent; source: ChangeSource; cancel: () => void; readonly canceled: boolean; } | { reason: \&#x22;item-removed\&#x22;; event?: undefined; source: ChangeSource; cancel: () => void; readonly canceled: boolean; }) => void&#x22;,&#x22;default&#x22;:null,&#x22;description&#x22;:&#x22;Runs when another tab is selected.&#x22;,&#x22;required&#x22;:false},{&#x22;name&#x22;:&#x22;orientation&#x22;,&#x22;type&#x22;:&#x22;\&#x22;horizontal\&#x22; | \&#x22;vertical\&#x22;&#x22;,&#x22;full&#x22;:&#x22;TabsOrientation&#x22;,&#x22;default&#x22;:null,&#x22;description&#x22;:&#x22;Controls the layout and arrow-key axis.&#x22;,&#x22;required&#x22;:false},{&#x22;name&#x22;:&#x22;activation&#x22;,&#x22;type&#x22;:&#x22;\&#x22;manual\&#x22; | \&#x22;automatic\&#x22;&#x22;,&#x22;full&#x22;:&#x22;\&#x22;manual\&#x22; | \&#x22;automatic\&#x22;&#x22;,&#x22;default&#x22;:null,&#x22;description&#x22;:&#x22;Automatic selects on focus; manual waits for Enter or Space.&#x22;,&#x22;required&#x22;:false},{&#x22;name&#x22;:&#x22;loop&#x22;,&#x22;type&#x22;:&#x22;boolean&#x22;,&#x22;full&#x22;:&#x22;boolean&#x22;,&#x22;default&#x22;:null,&#x22;description&#x22;:&#x22;Wraps arrow-key focus at either end.&#x22;,&#x22;required&#x22;:false},{&#x22;name&#x22;:&#x22;hiddenUntilFound&#x22;,&#x22;type&#x22;:&#x22;boolean&#x22;,&#x22;full&#x22;:&#x22;boolean&#x22;,&#x22;default&#x22;:null,&#x22;description&#x22;:&#x22;Keeps panels available for find in page.&#x22;,&#x22;required&#x22;:false},{&#x22;name&#x22;:&#x22;controller&#x22;,&#x22;type&#x22;:&#x22;function&#x22;,&#x22;full&#x22;:&#x22;{ getValue: () => string | null; setValue: (value: string | null, options?: TabsChangeOptions) => boolean; select: (value: string, options?: TabsChangeOptions) => boolean; focus: () => void; }&#x22;,&#x22;default&#x22;:null,&#x22;description&#x22;:&#x22;Selects and focuses tabs from anywhere.&#x22;,&#x22;required&#x22;:false}]" />

### TabsTab [#tabstab]

Renders a `<button>`, and takes its props too.

<PropsTable rows="[{&#x22;name&#x22;:&#x22;value&#x22;,&#x22;type&#x22;:&#x22;string&#x22;,&#x22;full&#x22;:&#x22;string&#x22;,&#x22;default&#x22;:null,&#x22;description&#x22;:&#x22;Identifies the tab and pairs it with the panel of the same value.&#x22;,&#x22;required&#x22;:true},{&#x22;name&#x22;:&#x22;disabled&#x22;,&#x22;type&#x22;:&#x22;boolean&#x22;,&#x22;full&#x22;:&#x22;boolean&#x22;,&#x22;default&#x22;:null,&#x22;description&#x22;:&#x22;Keeps focusable tabs from being selected.&#x22;,&#x22;required&#x22;:false}]" />

### TabsPanel [#tabspanel]

Renders a `<div>`, and takes its props too.

<PropsTable rows="[{&#x22;name&#x22;:&#x22;value&#x22;,&#x22;type&#x22;:&#x22;string&#x22;,&#x22;full&#x22;:&#x22;string&#x22;,&#x22;default&#x22;:null,&#x22;description&#x22;:&#x22;The value of the tab this panel belongs to.&#x22;,&#x22;required&#x22;:true},{&#x22;name&#x22;:&#x22;keepMounted&#x22;,&#x22;type&#x22;:&#x22;boolean&#x22;,&#x22;full&#x22;:&#x22;boolean&#x22;,&#x22;default&#x22;:&#x22;false&#x22;,&#x22;description&#x22;:&#x22;Retains inactive panel DOM.&#x22;,&#x22;required&#x22;:false},{&#x22;name&#x22;:&#x22;hiddenUntilFound&#x22;,&#x22;type&#x22;:&#x22;boolean&#x22;,&#x22;full&#x22;:&#x22;boolean&#x22;,&#x22;default&#x22;:null,&#x22;description&#x22;:&#x22;Whether the panel stays findable with `hidden=\&#x22;until-found\&#x22;` while its tab isn't selected. Overrides the tabs'.&#x22;,&#x22;required&#x22;:false}]" />

### TabsTabIcon [#tabstabicon]

Renders a `<span>`, and takes its props too.

<PropsTable rows="[{&#x22;name&#x22;:&#x22;mirror&#x22;,&#x22;type&#x22;:&#x22;boolean&#x22;,&#x22;full&#x22;:&#x22;boolean&#x22;,&#x22;default&#x22;:&#x22;false&#x22;,&#x22;description&#x22;:&#x22;Flips the icon horizontally in right-to-left text, for icons that point a way, like arrows and chevrons. Icons that picture a thing, like a clock or a check, stay as they are.&#x22;,&#x22;required&#x22;:false}]" />

### Other parts [#other-parts]

These take the props of the element they render, and nothing else:

* `TabsList`: a `<div>`
* `TabsPanels`: a `<div>`
* `TabsIndicator`: a `<span>`

## Keyboard [#keyboard]

| Key              | What it does                                     |
| ---------------- | ------------------------------------------------ |
| <kbd>← →</kbd>   | Moves to the previous or next tab.               |
| <kbd>Home</kbd>  | Moves to the first tab.                          |
| <kbd>End</kbd>   | Moves to the last tab.                           |
| <kbd>Enter</kbd> | Selects the focused tab, with manual activation. |

## Accessibility [#accessibility]

Keyboard, focus and screen-reader behaviour come from UI SDK and are not changed. More in [Accessibility](/docs/accessibility).

## Swap the import [#swap-the-import]

Already using UI SDK's tabs with your own styles? Keep your markup and change one line. The primitive adds motion and nothing else.

```tsx
// Before
import { … } from "@ui-sdk/react/tabs"

// After: same parts, same props, now animated
import { … } from "@/components/keyframery/primitives/tabs"
```

## Questions

### How does the animated Tabs for UI SDK move?

Stretch: The key stretches across the list toward the tab you pick, then closes up. Fade: Label colours flip exactly at the key's edge as it passes. Direction: The panel slides in from the side you moved to.

### Do I need Motion or Framer Motion for the animated Tabs?

No. Every move is plain CSS, so there is nothing to install besides the component and UI SDK.

### Can I keep my own styling and only take the motion?

Yes. Import from `@/components/keyframery/primitives/tabs` instead. It has the same parts and props as `@ui-sdk/react/tabs` and adds motion only.

### What happens to the Tabs when someone turns on reduced motion?

Nothing moves. State changes happen at once, or with a short fade.
