Tabs
Switch between related views in the same place.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- Built on radix-ui/Tabs
- 4 parts, named exports
- role=tablist, tab and tabpanel with aria-selected and aria-controls.
- Arrow keys move between tabs, Home and End jump; only the active tab is a Tab stop.
- Give the list an accessible name with aria-label.
- Styles in one file:
tabs.css
Import
import '@monoline/css';
import {Tabs} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add tabs
It needs radix-ui; install it if your project does not have it:
npm install radix-ui
Usage
import {Tabs, TabsContent, TabsList, TabsTrigger} from '@monoline/react';
<Tabs defaultValue="overview">
<TabsList aria-label="Project">
<TabsTrigger value="overview">Overview</TabsTrigger>
<TabsTrigger value="activity">Activity</TabsTrigger>
<TabsTrigger value="settings">Settings</TabsTrigger>
</TabsList>
<TabsContent value="overview">Overview content.</TabsContent>
<TabsContent value="activity">Activity content.</TabsContent>
<TabsContent value="settings">Settings content.</TabsContent>
</Tabs>
Anatomy
Import the parts you need and nest them like this.
import {Tabs, TabsList, TabsTrigger, TabsContent} from '@monoline/react';
<Tabs>
<TabsList />
<TabsTrigger />
<TabsContent />
</Tabs>
Examples
Horizontal
Vertical
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
| Attribute | Stylesheet |
|---|---|
[data-orientation="horizontal"] | tabs.css |
[data-orientation="vertical"] | tabs.css |
[data-state="active"] | tabs.css |
[aria-current="page"] | 18-navigation.css |
[aria-current="step"] | 18-navigation.css |
[aria-selected="true"] | 18-navigation.css |
[data-state="done"] | 18-navigation.css |
CSS classes
| Class | Stylesheet |
|---|---|
.tabs-content | tabs.css |
.tabs-list | tabs.css |
.tabs-root | tabs.css |
.tabs-trigger | tabs.css |
.brand | 18-navigation.css |
.crumbs | 18-navigation.css |
.pager | 18-navigation.css |
.step | 18-navigation.css |
.steps | 18-navigation.css |
.tab | 18-navigation.css |
.tabpanel | 18-navigation.css |
.topbar | 18-navigation.css |
.topbar-nav | 18-navigation.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.tabs-content {
border-color: var(--accent);
}
.tabs-content[data-orientation="horizontal"] {
background: var(--wash);
}
Try the props
Change a prop and the component above updates; the code below is what you would write. To edit the code itself, use the Playground.
Overview content.
example.tsx
<Tabs defaultValue="overview">
<TabsList aria-label="Project">
<TabsTrigger value="overview">Overview</TabsTrigger>
<TabsTrigger value="activity">Activity</TabsTrigger>
<TabsTrigger value="settings">Settings</TabsTrigger>
</TabsList>
<TabsContent value="overview">Overview content.</TabsContent>
<TabsContent value="activity">Activity content.</TabsContent>
<TabsContent value="settings">Settings content.</TabsContent>
</Tabs>
Accessibility
- role=tablist, tab and tabpanel with aria-selected and aria-controls.
- Arrow keys move between tabs, Home and End jump; only the active tab is a Tab stop.
- Give the list an accessible name with aria-label.
Keyboard
| Keys | Action |
|---|---|
| Arrow keys | Move between tabs |
| Home / End | Jump |