Tabs
Switch between related panels in the same place, with arrow-key and Home/End navigation.
Use tabs to split related content into views that people switch between without leaving the page. Each tab shows one panel. Don't use tabs for steps that must be done in order, or for navigation between pages.
import { Tab, TabList, TabPanel, Tabs } from "@aloxe/react";
export default function TabsBasic() {
return (
<Tabs defaultValue="overview" className="w-full max-w-md">
<TabList aria-label="Project">
<Tab value="overview">Overview</Tab>
<Tab value="activity">Activity</Tab>
<Tab value="settings">Settings</Tab>
</TabList>
<TabPanel value="overview" className="aloxe-text-body-md text-ax-text-secondary">
3 open issues, last deploy 2 hours ago.
</TabPanel>
<TabPanel value="activity" className="aloxe-text-body-md text-ax-text-secondary">
Ada merged 4 pull requests this week.
</TabPanel>
<TabPanel value="settings" className="aloxe-text-body-md text-ax-text-secondary">
Rename the project, change its visibility or delete it.
</TabPanel>
</Tabs>
);
}Installation
npm i @aloxe/react @aloxe/tokensThen add the CSS imports from Installation.
Usage
import { Tab, TabList, TabPanel, Tabs } from "@aloxe/react";
<Tabs defaultValue="overview">
<TabList aria-label="Project">
<Tab value="overview">Overview</Tab>
<Tab value="activity">Activity</Tab>
</TabList>
<TabPanel value="overview">…</TabPanel>
<TabPanel value="activity">…</TabPanel>
</Tabs>Match each Tab with a TabPanel by value. Hidden panels are unmounted unless you pass keepMounted.
Examples
With icons
A 16 px icon before the label. A disabled tab is skipped by the arrow keys.
import { Tab, TabList, TabPanel, Tabs } from "@aloxe/react";
import { Bell, CreditCard, User } from "lucide-react";
export default function TabsWithIcons() {
return (
<Tabs defaultValue="profile" className="w-full max-w-md">
<TabList aria-label="Account settings">
<Tab value="profile">
<User />
Profile
</Tab>
<Tab value="billing">
<CreditCard />
Billing
</Tab>
<Tab value="notifications" disabled>
<Bell />
Notifications
</Tab>
</TabList>
<TabPanel value="profile" className="aloxe-text-body-md text-ax-text-secondary">
Your name, photo and public handle.
</TabPanel>
<TabPanel value="billing" className="aloxe-text-body-md text-ax-text-secondary">
Payment method, invoices and seats.
</TabPanel>
</Tabs>
);
}Vertical
orientation="vertical" puts the tabs in a column, for settings pages with many sections. Up and Down move between them.
import { Tab, TabList, TabPanel, Tabs } from "@aloxe/react";
export default function TabsVertical() {
return (
<Tabs defaultValue="general" orientation="vertical" className="w-full max-w-md">
<TabList aria-label="Settings">
<Tab value="general">General</Tab>
<Tab value="members">Members</Tab>
<Tab value="api">API keys</Tab>
</TabList>
<TabPanel value="general" className="aloxe-text-body-md text-ax-text-secondary">
Workspace name, URL and default language.
</TabPanel>
<TabPanel value="members" className="aloxe-text-body-md text-ax-text-secondary">
8 members, 2 pending invites.
</TabPanel>
<TabPanel value="api" className="aloxe-text-body-md text-ax-text-secondary">
Create and revoke keys for the REST API.
</TabPanel>
</Tabs>
);
}Controlled
Pass value and onValueChange to change the tab from your own code.
Step 1 of 3
"use client";
import { Button, Tab, TabList, TabPanel, Tabs } from "@aloxe/react";
import { useState } from "react";
const steps = ["account", "workspace", "invite"] as const;
type Step = (typeof steps)[number];
export default function TabsControlled() {
const [step, setStep] = useState<Step>("account");
const next = steps[steps.indexOf(step) + 1];
return (
<Tabs
value={step}
onValueChange={(value) => setStep(value as Step)}
className="w-full max-w-md"
>
<TabList aria-label="Setup steps">
<Tab value="account">Account</Tab>
<Tab value="workspace">Workspace</Tab>
<Tab value="invite">Invite</Tab>
</TabList>
{steps.map((value) => (
<TabPanel key={value} value={value} className="flex flex-col items-start gap-3">
<p className="aloxe-text-body-md text-ax-text-secondary">
Step {steps.indexOf(value) + 1} of {steps.length}
</p>
{next ? (
<Button size="sm" onClick={() => setStep(next)}>
Next step
</Button>
) : (
<Button size="sm" variant="secondary" onClick={() => setStep("account")}>
Start over
</Button>
)}
</TabPanel>
))}
</Tabs>
);
}Accessibility
| Key | Action |
|---|---|
| Tab | Moves focus to the selected tab, then into its panel. |
| Right and Left | Move between tabs and wrap around (Down and Up when vertical). |
| Home and End | Move to the first or last tab. |
| Enter or Space | Selects the focused tab. With activateOnFocus, arrow keys select too. |
- Follows the WAI-ARIA tabs pattern:
tablist,tabandtabpanelroles, witharia-selectedandaria-controls. - Give the
TabListanaria-labelwhen there is no heading right above it. - The selected tab is marked by a 2 px bar and a stronger text colour, not by colour alone.
API reference
Every part accepts className and renders a data-aloxe attribute you can target in CSS, such as [data-aloxe="tabs"].
Tabs
Extends Base UI Tabs.Root.
| Prop | Type | Default | Description |
|---|---|---|---|
| defaultValue | Value | The tab selected first when uncontrolled. Defaults to the first tab. | |
| value | Value | Controlled value. Pair with onValueChange. | |
| onValueChange | (value: Value, details) => void | Called when the user selects a tab. | |
| orientation | "horizontal" | "vertical" | "horizontal" | Vertical puts the tabs in a column on the left and uses Up and Down arrows. |
| className | string | Merged with the default classes. |
TabList
Extends Base UI Tabs.List.
| Prop | Type | Default | Description |
|---|---|---|---|
| activateOnFocus | boolean | false | Selects a tab as soon as arrow keys move focus to it, instead of on Enter or Space. |
| aria-label | string | Names the tab list when there is no heading right above it. |
Tab
Extends Base UI Tabs.Tab.
| Prop | Type | Default | Description |
|---|---|---|---|
| value (required) | Value | Matches the TabPanel with the same value. | |
| disabled | boolean | false | Skipped by arrow keys and not selectable. |
TabPanel
Extends Base UI Tabs.Panel.
| Prop | Type | Default | Description |
|---|---|---|---|
| value (required) | Value | Shown when the Tab with the same value is selected. | |
| keepMounted | boolean | false | Keeps hidden panels in the DOM, e.g. to preserve form state. |
Figma
Matches the Tabs and Tab components. The Figma Tab Selected state is the value on Tabs; Label is the Tab content.
See Figma for where to get the file and how its names map to code.