Animated Tabs

Animated

Tabs with a pill that travels to the selected trigger.

Source
$npx @dinachi/cli@latest add animated-tabs

Everything at a glance.

transition
indicatorClassName
disabled

Usage

import {
  AnimatedTabs,
  AnimatedTabsContent,
  AnimatedTabsList,
  AnimatedTabsTrigger,
} from "@/components/ui/animated-tabs"

export function ProjectViews() {
  return (
    <AnimatedTabs aria-label="Views" defaultValue="overview">
      <AnimatedTabsList>
        <AnimatedTabsTrigger value="overview">Overview</AnimatedTabsTrigger>
        <AnimatedTabsTrigger value="activity">Activity</AnimatedTabsTrigger>
      </AnimatedTabsList>
      <AnimatedTabsContent value="overview">Everything at a glance.</AnimatedTabsContent>
      <AnimatedTabsContent value="activity">Who changed what, and when.</AnimatedTabsContent>
    </AnimatedTabs>
  )
}

Examples

Everything at a glance.

The pill travels to the tab you click.
import {
  AnimatedTabs,
  AnimatedTabsList,
  AnimatedTabsTrigger,
  AnimatedTabsContent,
} from '@/components/ui/animated-tabs';

export function Example() {
  return (
    <AnimatedTabs defaultValue="overview">
      <AnimatedTabsList>
        <AnimatedTabsTrigger value="overview">Overview</AnimatedTabsTrigger>
        <AnimatedTabsTrigger value="activity">Activity</AnimatedTabsTrigger>
        <AnimatedTabsTrigger value="settings">Settings</AnimatedTabsTrigger>
      </AnimatedTabsList>
      <AnimatedTabsContent value="overview">Everything at a glance.</AnimatedTabsContent>
      <AnimatedTabsContent value="activity">Who changed what, and when.</AnimatedTabsContent>
      <AnimatedTabsContent value="settings">Names, keys, and members.</AnimatedTabsContent>
    </AnimatedTabs>
  );
}

Notes

Motion tier

Needs motion. add --all skips it; install with add --motion or by name.

When to use it

  • A short, stable strip of three to five tabs: a settings pane, a profile, a chart's time range.
  • For a strip that scrolls or has a dozen entries, use Tabs.

Styling

  • The selected tab carries data-active. Recolour its label with data-[active]:text-primary-foreground when the pill is dark.
  • The pill is measured, so labels of uneven width need no offsets.

Behaviour

  • Pointer changes travel; keyboard changes and reduced motion cut.
  • The default spring has no bounce.

API

valueany
Controlled selected tab.
defaultValueany
Starting tab when uncontrolled. The pill shows only on a matching tab, so set one.
onValueChange
agent
(value, details) => void
Runs for people and agents. details.cancel() refuses the change.
transitionTransition = { type: "spring", bounce: 0, duration: 0.3 }
Overrides the pill's motion.
orientation"horizontal" | "vertical" = "horizontal"
Which arrow keys move between tabs.
aria-label
agent
string
Names the tabs. Also the name the agent reads.

Agent

Inside an AgentProvider, it appears in agent.snapshot() as tabs.

Reads

label

The AnimatedTabs aria-label, or tabs when it has none.

value

The selected tab's label.

items

Every tab's label, in order.

disabled

True when every tab is disabled.

Actions

select("Activity")

Picks by label, then by value. A miss lists the tabs.

The agent clicks the tab, so the change runs through onValueChange. isAgentChange(details) is true for it, and details.cancel() refuses it; the agent is told the app refused. A disabled tab refuses on its own.

await agent.act({
  steps: [{ ref: "tabs", action: "select", args: ["Activity"] }],
})

Accessibility

  • Roving focus, aria-selected and aria-controls come from Base UI Tabs.
  • Tablist, tab and tabpanel roles; each panel is labelled by its tab.
  • The pill is aria-hidden; selection is announced via aria-selected.
  • Give AnimatedTabs an aria-label when a page has several tab sets. The agent reads it.