# Animated Tabs

> Tabs with a sliding pill indicator and panels that fade in the direction of travel. Full WAI-ARIA tabs keyboard support with Arrow keys, Home and End.

- Kind: Motion component (Navigation)
- Docs: https://ui.minidev.pro/docs/animated-tabs
- Source (registry JSON with the full file): https://ui.minidev.pro/r/animated-tabs.json
- License: MIT. One file, yours to edit after install.

## When to use

Follows the WAI-ARIA tabs pattern: roving focus, Arrow keys, Home and End, automatic activation. Pass `tabs` as data (id, label, content). Works uncontrolled (`defaultValue`) or controlled (`value` + `onValueChange`). Use it for a marketing or overview panel with a few views; for app navigation tabs built from parts use Tabs, and for a compact toggle between options use SegmentedControl.

## Installation

### shadcn CLI (copies the source into your project)

```bash
npx shadcn@latest add @minidev/animated-tabs
```

Writes `components/ui/animated-tabs.tsx` and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/animated-tabs.json`.

### npm package

```bash
npm i minidev-ui-kit motion
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

```tsx
import { AnimatedTabs } from "@/components/ui/animated-tabs"
```

From the npm package:

```tsx
import { AnimatedTabs } from "minidev-ui-kit/premium/animated-tabs"
```

## Usage

```tsx
import { AnimatedTabs } from "@/components/ui/animated-tabs"

export function Example() {
  return (
    <AnimatedTabs />
  )
}
```

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `tabs` | `Tab[]` | `DEMO` | no |  |
| `value` | `string` | - | no | Active tab id when controlled. |
| `defaultValue` | `string` | - | no | Initial tab id when uncontrolled. Defaults to the first tab. |
| `onValueChange` | `(id: string) => void` | - | no | Called with the new tab id on click or arrow key. |
| `label` | `string` | `"Sections"` | no | Accessible name of the tab list. |
| `className` | `string` | - | no |  |

## Examples

### Custom tabs

Each tab is an id, a label and any content node; the pill slides and the panel fades toward the direction of travel.

```tsx
const INVOICE_TABS = [
  { id: "summary", label: "Summary", content: <p>INV-2041 for Northwind Traders, $12,400.00, issued Sep 24 and due Oct 24. Sent by Maya Chen.</p> },
  { id: "items", label: "Line items", content: <p>Implementation (40h at $250), onboarding workshop, and 12 months of the Growth plan billed annually.</p> },
  { id: "payments", label: "Payments", content: <p>No payments yet. A reminder went out on Oct 10 and Northwind confirmed the Friday payment run.</p> },
  { id: "history", label: "History", content: <p>Created Sep 24, approved by Theo Okafor Sep 25, sent Sep 25, reminder Oct 10.</p> },
]

<AnimatedTabs tabs={INVOICE_TABS} />
```

### Default tab and change handler

defaultValue picks the starting tab and onValueChange reports the id, which is enough to sync the tab with the URL.

```tsx
// INVOICE_TABS is the list from the "Custom tabs" example.
function TrackedDemo() {
  const [tab, setTab] = React.useState("items")
  const label = INVOICE_TABS.find((t) => t.id === tab)?.label
  return (
    <div className="flex w-full max-w-lg flex-col gap-3">
      <AnimatedTabs tabs={INVOICE_TABS} defaultValue="items" onValueChange={setTab} />
      <p className="text-xs text-fg-muted">
        Viewing <span className="font-medium text-fg">{label}</span> (id <code className="font-mono">{tab}</code>)
      </p>
    </div>
  )
}
```

### Rich panel content

Panels take whole components, so a record view can switch between a description list and usage bars.

```tsx
<AnimatedTabs
  tabs={[
    {
      id: "account",
      label: "Account",
      content: (
        <DescriptionList
          className="max-w-none gap-4"
          items={[
            { label: "Customer", value: "Northwind Traders" },
            { label: "Owner", value: "Priya Raman" },
            { label: "Plan", value: "Growth, annual" },
            { label: "Renews", value: "Jan 9, 2027" },
          ]}
        />
      ),
    },
    {
      id: "usage",
      label: "Usage",
      content: (
        <UsageBreakdown
          className="max-w-none"
          items={[
            { label: "Invoices sent", used: 1840, limit: 2500 },
            { label: "Seats", used: 18, limit: 25 },
            { label: "Storage (GB)", used: 38, limit: 50 },
          ]}
        />
      ),
    },
  ]}
/>
```

## Keyboard interactions

| Key | Action |
| --- | --- |
| `ArrowRight` or `ArrowLeft` | Moves focus to the next or previous tab and selects it. Wraps at both ends. |
| `Home` or `End` | Selects the first or last tab. |
| `Tab` | Moves focus from the selected tab into the panel. |

## Accessibility

- The list has `role="tablist"` and `aria-label` from `label` (default "Sections"). Each tab is a `<button role="tab">` with `aria-selected` and `aria-controls`, and only the selected tab has `tabIndex={0}`.
- The panel has `role="tabpanel"`, `aria-labelledby` pointing at its tab and `tabIndex={0}`, so keyboard users can reach text-only panels.
- With reduced motion the pill jumps instead of sliding, and the panel swaps with no slide, blur or delay.

## FAQ

### How is AnimatedTabs different from Tabs?

AnimatedTabs takes one `tabs` array of `{ id, label, content }` and selects a tab as soon as an arrow key reaches it. [`Tabs`](https://ui.minidev.pro/docs/tabs) is built from parts on Base UI, where arrow keys only move focus until you press Enter or Space (unless you set `activateOnFocus`), and it supports vertical orientation and count badges.

### How do I control which tab is open?

Pass `value` and `onValueChange`. `onValueChange` fires with the new `id` only when it differs from the current one. If `value` matches no tab, the first tab is shown instead of an empty panel.

### Why does a form in another tab lose what I typed?

Only the active panel is rendered; switching tabs unmounts the old one. Keep the form state above AnimatedTabs, or use [`Tabs`](https://ui.minidev.pro/docs/tabs) with `keepMounted` on `TabsContent`.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `motion`

## Related

- [Tabs](https://ui.minidev.pro/docs/tabs/md): Tabs on Base UI with a raised thumb or a line underline that springs to the active tab, optional count badges, vertical orientation and roving keyboard focus.
- [Segmented Control](https://ui.minidev.pro/docs/segmented-control/md): Segmented control with a raised thumb that springs between options, arrow, Home and End key support, icons, badges, three sizes and reduced motion support.
- [Before After Wipe](https://ui.minidev.pro/docs/before-after-wipe/md): A before and after comparison slider in React: drag the handle or use the labelled range input to wipe between two layouts across the full width.
- [Scroll Progress Rail](https://ui.minidev.pro/docs/scroll-progress-rail/md): A React reading progress bar that fills with page scroll on a spring, with section labels such as intro, product, proof and pricing shown beneath it.
- [Dock](https://ui.minidev.pro/docs/dock/md): A macOS style dock for React: icons magnify under the pointer with spring physics and show a label. Real buttons or links, keyboard reachable and labelled.
- [Back Link](https://ui.minidev.pro/docs/back-link/md): Small back navigation link with a left arrow icon, muted text that darkens on hover and a visible focus ring. Defaults to the label Back and accepts any href.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
