Documentation / Navigation & actions
Tabs
Tabs to switch between several views of the same context without leaving the page. The component is composed: Tabs holds the state, TabsList lines up the TabsTriggers, and each TabsContent shows when its value is the active tab’s.
Uncontrolled with defaultValue (set it, otherwise no tab is active at first), controlled with value + onValueChange. Four styles (underline, pills, enclosed, soft), six colours, three sizes, horizontal or vertical. An inactive panel is unmounted, unless forceMount keeps it hidden in the DOM.
From the keyboard, one tab is in the tab order: the arrow keys, Home and End move from one to the next, skipping disabled tabs, and the tab they land on is selected. The arrows follow the layout (up and down when vertical) and the reading direction. Each panel is named by its tab (aria-labelledby). Client component ("use client").
Examples
Basic usage
The default underline; defaultValue names the tab open at first.
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@synertech/ui";
export function Basic() {
return (
<Tabs defaultValue="apercu">
<TabsList>
<TabsTrigger value="apercu">Aperçu</TabsTrigger>
<TabsTrigger value="activite">Activité</TabsTrigger>
<TabsTrigger value="parametres">Paramètres</TabsTrigger>
</TabsList>
<TabsContent value="apercu">Résumé du projet et indicateurs clés.</TabsContent>
<TabsContent value="activite">Les dernières modifications de l’équipe.</TabsContent>
<TabsContent value="parametres">Nom, visibilité et membres du projet.</TabsContent>
</Tabs>
);
}Styles and colours
variant changes the shape of the active tab, color its hue.
import { Tabs, TabsList, TabsTrigger } from "@synertech/ui";
export function Variants() {
return (
<div className="space-y-6">
{(["pills", "enclosed", "soft"] as const).map((variant) => (
<Tabs key={variant} defaultValue="mois" variant={variant} color="primary" size="sm">
<TabsList gap={variant === "enclosed" ? "none" : "sm"}>
<TabsTrigger value="semaine">Semaine</TabsTrigger>
<TabsTrigger value="mois">Mois</TabsTrigger>
<TabsTrigger value="annee">Année</TabsTrigger>
</TabsList>
</Tabs>
))}
</div>
);
}Icons, counter and disabled tab
icon and endIcon frame the label; disabled makes a tab unreachable.
import { Badge, Tabs, TabsContent, TabsList, TabsTrigger } from "@synertech/ui";
const UserIcon = () => (
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2} aria-hidden="true">
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"
/>
</svg>
);
export function WithIcons() {
return (
<Tabs defaultValue="profil" variant="pills" fullWidth>
<TabsList>
<TabsTrigger value="profil" icon={<UserIcon />}>
Profil
</TabsTrigger>
<TabsTrigger
value="messages"
endIcon={
<Badge size="sm" color="error">
4
</Badge>
}
>
Messages
</TabsTrigger>
<TabsTrigger value="equipe" disabled>
Équipe
</TabsTrigger>
</TabsList>
<TabsContent value="profil">Vos informations personnelles.</TabsContent>
<TabsContent value="messages">Quatre messages non lus.</TabsContent>
</Tabs>
);
}Vertical tabs
orientation="vertical" puts the list to the left of the panels, like a settings page.
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@synertech/ui";
export function Vertical() {
return (
<Tabs defaultValue="general" orientation="vertical" variant="soft">
<TabsList>
<TabsTrigger value="general">Général</TabsTrigger>
<TabsTrigger value="securite">Sécurité</TabsTrigger>
<TabsTrigger value="notifications">Notifications</TabsTrigger>
</TabsList>
<TabsContent value="general" className="mt-0">
Langue, fuseau horaire et format des dates.
</TabsContent>
<TabsContent value="securite" className="mt-0">
Mot de passe et double authentification.
</TabsContent>
<TabsContent value="notifications" className="mt-0">
E-mails et alertes dans l’application.
</TabsContent>
</Tabs>
);
}Controlled mode
value and onValueChange let the application switch tabs, here from a link.
import { useState } from "react";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@synertech/ui";
export function Controlled() {
const [tab, setTab] = useState("commande");
return (
<Tabs value={tab} onValueChange={setTab}>
<TabsList>
<TabsTrigger value="commande">Commande</TabsTrigger>
<TabsTrigger value="livraison">Livraison</TabsTrigger>
</TabsList>
<TabsContent value="commande">
3 articles, 128,40 €.{" "}
<button
type="button"
className="text-blue-600 underline"
onClick={() => setTab("livraison")}
>
Choisir la livraison
</button>
</TabsContent>
<TabsContent value="livraison">Livraison prévue sous 48 h.</TabsContent>
</Tabs>
);
}API reference
Components
import { Tabs } from "@synertech/ui";Props — TabsProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode |
— | |
className |
string |
— | |
color |
TabsColor |
"default" |
|
defaultValue |
string |
"" |
|
fullWidth |
boolean |
false |
|
onValueChange |
(value: string) => void |
— | |
orientation |
TabsOrientation |
"horizontal" |
|
size |
TabsSize |
"md" |
|
value |
string |
— | |
variant |
TabsVariant |
"underline" |
import { TabsContent } from "@synertech/ui";Props — TabsContentProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode |
— | |
value• |
string |
— | |
className |
string |
— | |
forceMount |
boolean |
false |
import { TabsList } from "@synertech/ui";Props — TabsListProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode |
— | |
bgColor |
string |
— | |
className |
string |
— | |
gap |
"none" | "sm" | "md" | "lg" |
"none" |
import { TabsTrigger } from "@synertech/ui";Props — TabsTriggerProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode |
— | |
value• |
string |
— | |
activeClassName |
string |
— | |
className |
string |
— | |
disabled |
boolean |
false |
|
endIcon |
ReactNode |
— | |
icon |
ReactNode |
— | |
inactiveClassName |
string |
— |
Types
TabsColor
Typetype TabsColor = "default" | "primary" | "secondary" | "success" | "warning" | "error"TabsOrientation
Typetype TabsOrientation = "horizontal" | "vertical"TabsSize
Typetype TabsSize = "sm" | "md" | "lg"TabsVariant
Typetype TabsVariant = "underline" | "pills" | "enclosed" | "soft"