Animated Tabs
MotionTabs 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.
Installation
npx shadcn@latest add @minidev/animated-tabs
MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/animated-tabs.json
Usage
import { AnimatedTabs } from "@/components/ui/animated-tabs"
export function Example() {
return (
<AnimatedTabs />
)
}
API reference
| Prop | Type | Default |
|---|---|---|
| tabs | Tab[] | DEMO |
| valueActive tab id when controlled. | string | - |
| defaultValueInitial tab id when uncontrolled. Defaults to the first tab. | string | - |
| onValueChangeCalled with the new tab id on click or arrow key. | (id: string) => void | - |
| labelAccessible name of the tab list. | string | "Sections" |
| className | string | - |
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.
Keyboard interactions
| Key | Action |
|---|---|
| ArrowRightorArrowLeft | Moves focus to the next or previous tab and selects it. Wraps at both ends. |
| HomeorEnd | Selects the first or last tab. |
| Tab | Moves focus from the selected tab into the panel. |
Accessibility
- The list has
role="tablist"andaria-labelfromlabel(default "Sections"). Each tab is a<button role="tab">witharia-selectedandaria-controls, and only the selected tab hastabIndex={0}. - The panel has
role="tabpanel",aria-labelledbypointing at its tab andtabIndex={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.
Frequently asked questions
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 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 with keepMounted on TabsContent.
Dependencies
npm
Built from
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.
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.
Rich panel content
Panels take whole components, so a record view can switch between a description list and usage bars.