Tabs
Splits content into named panels, so a user only sees one section at a time and can switch between them. Tabs is built on the Radix Tabs primitive, with full keyboard support built in.
Import
tsx
import { Tabs } from "@aizvi/ui";Basic example
tsx
<Tabs defaultValue="account">
<Tabs.List>
<Tabs.Trigger value="account">Account</Tabs.Trigger>
<Tabs.Trigger value="password">Password</Tabs.Trigger>
<Tabs.Trigger value="team">Team</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="account">
<Text>Update your name and email address here.</Text>
</Tabs.Content>
<Tabs.Content value="password">
<Text>Change your password here.</Text>
</Tabs.Content>
<Tabs.Content value="team">
<Text>Manage who else has access to this account.</Text>
</Tabs.Content>
</Tabs>Live preview
The parts
Tabs, the root part. It holds which tab is active, either on its own throughdefaultValue, or through thevalueandonValueChangeprops.Tabs.List, the row of tab buttons.Tabs.Trigger, a single tab button. Itsvalueprop must match thevalueon its matchingTabs.Content.Tabs.Content, the panel shown when its matching tab is active.
Controlled active tab
tsx
function ExampleTabs() {
const [tab, setTab] = useState("account");
return (
<Tabs value={tab} onValueChange={setTab}>
<Tabs.List>
<Tabs.Trigger value="account">Account</Tabs.Trigger>
<Tabs.Trigger value="password">Password</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="account">Account settings</Tabs.Content>
<Tabs.Content value="password">Password settings</Tabs.Content>
</Tabs>
);
}Vertical tabs
Pass orientation="vertical" to lay the tab list out as a column instead of a row, which also switches keyboard navigation to the up and down arrow keys.
tsx
<Tabs defaultValue="general" orientation="vertical">
<Tabs.List>
<Tabs.Trigger value="general">General</Tabs.Trigger>
<Tabs.Trigger value="billing">Billing</Tabs.Trigger>
</Tabs.List>
<Tabs.Content value="general">General settings</Tabs.Content>
<Tabs.Content value="billing">Billing settings</Tabs.Content>
</Tabs>Live preview
Disabled tab
tsx
<Tabs.Trigger value="team" disabled>
Team, coming soon
</Tabs.Trigger>Props
Tabsacceptsvalue,defaultValue,onValueChange,orientation, andactivationMode, matching the Radix Tabs root.orientationis one ofhorizontalorvertical, and the default ishorizontal.Tabs.Listaccepts every normal Radix Tabs list prop.Tabs.Triggeracceptsvalueanddisabled, plus every normal button attribute.Tabs.Contentacceptsvalue, plus every normal<div>attribute.
Accessibility
- Tabs.List gets
role="tablist", each trigger getsrole="tab", and each panel getsrole="tabpanel", matching what screen readers expect. - Once a tab has focus, the left and right arrow keys, or up and down for vertical tabs, move between tabs without needing the Tab key.
- Only the active panel is present for screen readers. Switching tabs announces the newly shown panel.