A modern React component that displays an animated tab switcher with a smooth visual indicator for the current selection. It’s perfect for navigation bars or section pickers with beautiful, theme-aware transitions.
This component was inspired by various design systems’ high-contrast, tactile tab selectors.
You can install the TabSelect component with the following CLI command, or copy the implementation manually:
1npx shadcn@latest add http://localhost:3000/r/tab-select.jsonTo use the TabSelect component, import it in your code:
1import TabSelect from '@/components/TabSelect';The TabSelect component accepts the following props:
| Prop | Type | Default | Description | Required |
|---|---|---|---|---|
tabs | string[] | - | Array of tab labels. | Yes |
activeTab | string | - | Optional controlled value for the current active tab. | No |
setActiveTab | (tab: string) => void | - | Function to set the active tab (for controlled usage). Internal state will be used if not provided. | No |
className | string | - | Class name for the overall tab group container. | No |
tabClassName | string | - | Class name for each tab button. | No |
gap | string | number | "2rem" | Spacing between tabs. | No |
1
2type TabSelectProps = {
3 tabs: string[];
4 activeTab?: string;
5 setActiveTab?: React.Dispatch<React.SetStateAction<string>> | ((tab: string) => void);
6 className?: string;
7 tabClassName?: string;
8 gap?: string | number;
9};
101<TabSelect tabs={['Home', 'Components', 'Pricing']} />1
2const [tab, setTab] = useState('Home');
3<TabSelect
4 tabs={['Home', 'Components', 'Pricing']}
5 activeTab={tab}
6 setActiveTab={setTab}
7/>
81<TabSelect
2 tabs={['Overview', 'Features', 'Pricing', 'FAQ']}
3 gap="1.5rem"
4 className="bg-blue-50 dark:bg-neutral-900"
5 tabClassName="text-base"
6/>gap prop to control distance between tabs.className or tabClassName for custom visual appearance.activeTab and setActiveTab) if you want to fully manage selected tab from parent state logic.tabs prop is required and must be a non-empty array of strings.activeTab and setActiveTab.cn from your utilities).