$npx @dinachi/cli@latest add animated-tabs
Everything at a glance.
transitionindicatorClassNamedisabledproject-tabs.tsx
import { AnimatedTabs, AnimatedTabsContent, AnimatedTabsList, AnimatedTabsTrigger } from "@/components/ui/animated-tabs"
const tabs = [
{ value: "overview", label: "Overview", body: "Everything at a glance." },
{ value: "activity", label: "Activity", body: "Who changed what, and when." },
{ value: "settings", label: "Settings", body: "Names, keys, and members." },
]
export function ProjectTabs() {
return (
<AnimatedTabs
aria-label="Project"
defaultValue="overview"
>
<AnimatedTabsList>
{tabs.map((tab) => (
<AnimatedTabsTrigger key={tab.value} value={tab.value}>
{tab.label}
</AnimatedTabsTrigger>
))}
</AnimatedTabsList>
{tabs.map((tab) => (
<AnimatedTabsContent key={tab.value} value={tab.value}>
{tab.body}
</AnimatedTabsContent>
))}
</AnimatedTabs>
)
}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>
);
}The pill themed without restyling the tab.
import {
AnimatedTabs,
AnimatedTabsList,
AnimatedTabsTrigger,
} from '@/components/ui/animated-tabs';
export function Example() {
return (
<AnimatedTabs defaultValue="week">
<AnimatedTabsList className="bg-transparent p-0">
{['Day', 'Week', 'Month'].map((label) => (
<AnimatedTabsTrigger
key={label}
value={label.toLowerCase()}
indicatorClassName="rounded-md bg-primary"
className="rounded-md data-[active]:text-primary-foreground"
>
{label}
</AnimatedTabsTrigger>
))}
</AnimatedTabsList>
</AnimatedTabs>
);
}Everything at a glance.
The selection held in React state.
import { useState } from 'react';
import {
AnimatedTabs,
AnimatedTabsList,
AnimatedTabsTrigger,
} from '@/components/ui/animated-tabs';
export function Example() {
const [value, setValue] = useState('overview');
return (
<AnimatedTabs value={value} onValueChange={(next) => setValue(next as string)}>
<AnimatedTabsList>
<AnimatedTabsTrigger value="overview">Overview</AnimatedTabsTrigger>
<AnimatedTabsTrigger value="activity">Activity</AnimatedTabsTrigger>
</AnimatedTabsList>
</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 withdata-[active]:text-primary-foregroundwhen 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
Runs for people and agents. agent
(value, details) => voiddetails.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
Names the tabs. Also the name the agent reads.agent
stringactivateOnFocusboolean = false
Selects on arrow key instead of Enter or Space.loopFocusboolean = true
Wraps arrow-key focus from the last tab to the first.valueany
Which panel it selects.indicatorClassNamestring
Class for the pill; themes it without restyling the tab.disabled
Skipped by the keyboard, refused for agents.agent
boolean = falsechildren
The tab label. Also the name the agent selects by.agent
ReactNodevalueany
The tab this panel belongs to.keepMountedboolean = false
Keeps the panel in the DOM while hidden.Agent
Inside an AgentProvider, it appears in agent.snapshot() as tabs.
Reads
labelThe AnimatedTabs aria-label, or tabs when it has none.
valueThe selected tab's label.
itemsEvery tab's label, in order.
disabledTrue 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
AnimatedTabsan aria-label when a page has several tab sets. The agent reads it.
Keyboard
←→Moves focus between tabs, or ↑ ↓ when vertical
HomeEndMoves focus to the first or last tab
SpaceEnterSelects the focused tab
TabMoves focus from the tab list into the panel
←→Moves focus between tabs, or ↑ ↓ when vertical
HomeEndMoves focus to the first or last tab
SpaceEnterSelects the focused tab
TabMoves focus from the tab list into the panel