shadcn.io is not affiliated with official shadcn/ui
Tabs examples · Advanced
Controlled Tabs for React
Three step tabs held in state, with Previous and Next buttons that move between them.
A wizard needs buttons that change the tab, so the selected tab lives in the demo's state instead of inside Tabs. Three steps (Basic Information, Configuration, Review and Confirm) come from one array, and Previous and Next move one step at a time. Use it for onboarding or a multi-step setup where people may still click a step directly.
Preview
Installation
FAQ
How does this demo control the selected tab?
The selected value is kept in state, starting at step1, and passed back to Tabs. Clicking a trigger or a button writes the same state.
Tabs gets value, and onValueChange receives the next value.
When are Previous and Next disabled?
Previous is disabled on the first step and Next on the last. Each button moves one place in the steps array.
Can the reader still click a step?
Yes. The three triggers are not disabled. Clicking one updates the same state the buttons write, so the buttons stay in sync.
Why are the three steps equal width?
TabsList has grid w-full grid-cols-3, so each of Step 1, Step 2 and Step 3 fills a column. The group is w-full max-w-2xl.
Related
- Basic TabsFour horizontal tabs that switch between
- Tabs with Badge CountsMailbox tabs with a badge after each
- Nested TabsProfile, Settings and Billing tabs, each
- Tabs with FormsLogin and Register tabs that each hold a
- Tabs with CardsFeatured, Popular and Recent tabs, each
- Tabs with TablesAll Users, Active and Inactive tabs, each