Tabs
A set of layered panels where only one is visible at a time.
Import
import { Tabs } from '@matix/components/tabs';Usage
Manage your account settings and preferences.
Controlled
Use value and onValueChange for controlled tab selection.
import { useState } from 'react';
function ControlledTabs() {
const [tab, setTab] = useState('one');
return (
<div>
<Tabs.Root value={tab} onValueChange={setTab}>
<Tabs.List>
<Tabs.Tab value="one">Tab One</Tabs.Tab>
<Tabs.Tab value="two">Tab Two</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="one">First panel content.</Tabs.Panel>
<Tabs.Panel value="two">Second panel content.</Tabs.Panel>
</Tabs.Root>
<span>Active: {tab}</span>
</div>
);
}Pill Variant
Set variant="pill" on Tabs.List for a segmented-control look with a raised active pill. Each Tabs.Tab takes the variant from its list through CSS, so you set it once.
A high-level view of your workspace.
A variant on one Tabs.Tab overrides the list variant for that tab only.
Vertical
Set orientation="vertical" on Tabs.Root to put the tabs in a column beside the panel. The active tab shows its indicator on the inline end, so it moves to the left side in RTL. ArrowUp and ArrowDown move between the tabs. Both variants support it.
Name, URL, and default language.
Keyboard Activation
An arrow key moves focus to the next tab and selects it at the same time. This is the WAI-ARIA "automatic activation" pattern, and Radix tabs do the same. matix sets activateOnFocus on Tabs.List to true by default. Base UI uses false by default.
If a panel is slow to render, set activateOnFocus={false}. Then the arrow keys only move focus, and Enter or Space selects the focused tab.
<Tabs.List activateOnFocus={false}>
<Tabs.Tab value="report">Report</Tabs.Tab>
<Tabs.Tab value="raw">Raw data</Tabs.Tab>
</Tabs.List>Disabled Tab
Individual tabs can be disabled while the rest remain interactive.
This tab is active.
Custom Styles
Use the sx prop on any sub-component to override styles.
import * as stylex from '@stylexjs/stylex';
const custom = stylex.create({
list: { borderBottom: '2px solid #e2e8f0' },
tab: { fontWeight: 600, letterSpacing: '-0.01em' },
panel: { padding: '16px 0' },
});
<Tabs.Root defaultValue="one">
<Tabs.List sx={custom.list}>
<Tabs.Tab value="one" sx={custom.tab}>
First
</Tabs.Tab>
<Tabs.Tab value="two" sx={custom.tab}>
Second
</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="one" sx={custom.panel}>
Styled first panel.
</Tabs.Panel>
<Tabs.Panel value="two" sx={custom.panel}>
Styled second panel.
</Tabs.Panel>
</Tabs.Root>;Server Components
Tabs is a client component. A Server Component cannot read a property of a client component, so Tabs.Root is undefined there. In a Server Component, import the named parts. Each Tabs.<Part> is also exported as Tabs<Part>.
import { TabsRoot, TabsList, TabsTab, TabsPanel } from '@matix/components/tabs';In a client component, both forms work.
API Reference
| Component | Prop | Type | Default | Description |
|---|---|---|---|---|
Tabs.Root | defaultValue | string | — | Initially active tab (uncontrolled) |
Tabs.Root | value | string | — | Active tab (controlled) |
Tabs.Root | onValueChange | (value: string) => void | — | Called when the active tab changes |
Tabs.Root | orientation | 'horizontal' | 'vertical' | 'horizontal' | Lays the tabs out in a row or a column |
Tabs.Root | sx | StyleXStyles | — | StyleX style override |
Tabs.List | variant | 'line' | 'pill' | 'line' | Visual style. The tabs in the list take it too |
Tabs.List | activateOnFocus | boolean | true | Select a tab when an arrow key focuses it |
Tabs.List | sx | StyleXStyles | — | StyleX style override |
Tabs.Tab | value | string | — | Unique identifier for the tab |
Tabs.Tab | variant | 'line' | 'pill' | — | Overrides the list variant for this tab |
Tabs.Tab | disabled | boolean | false | Disables the tab |
Tabs.Tab | sx | StyleXStyles | — | StyleX style override |
Tabs.Panel | value | string | — | Matches the corresponding Tabs.Tab value |
Tabs.Panel | sx | StyleXStyles | — | StyleX style override |
All other props on each sub-component are forwarded to the underlying Base UI element.
Accessibility
- Built on Base UI
Tabs— implements WAI-ARIA Tabs pattern withrole="tablist",role="tab", androle="tabpanel". - Each tab is associated with its panel via
aria-controlsandaria-labelledby. - Selected tab receives
aria-selected="true". - Disabled tabs are excluded from the tab sequence and marked with
aria-disabled. - Focus ring is visible on keyboard navigation only (
:focus-visible).
Keyboard
| Key | Action |
|---|---|
ArrowRight | Moves focus to the next tab and selects it |
ArrowLeft | Moves focus to the previous tab and selects it |
ArrowDown / ArrowUp | The same, when orientation="vertical" |
Home | Moves focus to the first tab and selects it |
End | Moves focus to the last tab and selects it |
Enter / Space | Activates the focused tab |
With activateOnFocus={false}, the arrow keys, Home, and End only move focus.