- Docs
- Components
- Navigation
Tabs
Views of the same thing, one at a time. One Tab stop; the arrow keys move between them.
- Import
- @qeetrix/react
- Status
- StableSince 0.0.2
- Renders
<div role="tablist">Server-rendered- Tested
- WCAG 2.2 AAaxe on every pull request
01
Import
// From the package: a build keeps only what it uses.
import { Tabs, TabsList, Tab, TabsPanel } from "@qeetrix/react";
// Or from its own path.
import { Tabs, TabsList, Tab, TabsPanel } from "@qeetrix/react/tabs";02
Props
And every native attribute of the element it renders.
| Prop | Type | Default | What it does |
|---|---|---|---|
Tabs: value · defaultValue | string | the first tab | The selected tab's value. |
Tabs: onValueChange | (value, details) => void | — | Called with the new value. |
Tabs: orientation | "horizontal" | "vertical" | "horizontal" | Vertical carries the line and the bar on the start edge. |
TabsList: variant | "line" | "contained" | "line" | Line for a page's views; contained, a segmented strip, for a card's. |
TabsList: activateOnFocus | boolean | true | Select as focus moves; off for slow panels, so Enter or Space selects. |
Tab: value | string | required | Matches its TabsPanel's value. |
Tab: icon · filledWhenSelected | IconSource · boolean | — · true | A 16px leading icon, filled while selected; false keeps the outline. An icon with no filled drawing keeps its outline. |
Tab: badge | ReactNode | — | A number, formatted for the locale as a neutral Badge; or your own Badge. |
Tab: disabled | boolean | false | Can't be selected; it stays reachable by the arrow keys, so it's read. |
TabNavLink: current · icon · filledWhenSelected | boolean · IconSource · boolean | false · — · true | In a TabNav: aria-current="page" and the bar; an icon filled while current, as a Tab's. |
TabsPanel: keepMounted | boolean | false | Keep a hidden panel in the page, so its state survives. |
03
Parts
Each part carries a data-slot, for tests and placement.
| data-slot | Element | What it is |
|---|---|---|
tabs | <div> | The root: data-orientation. |
tabs-list | <div role="tablist"> | data-variant. |
tab | <button role="tab"> | aria-selected; data-active. |
tab-label | <span> | The label and its count. |
tab-badge | <span> | The count. |
tabs-indicator | <span> | The bar. |
tabs-panel | <div role="tabpanel"> | One view. |
04
In the address
Keep the view in the URL, so it can be shared and Back returns to it.
const { tab = "profile" } = useSearch();
<Tabs value={tab} onValueChange={(value) => navigate({ search: { tab: value } })}>
…
</Tabs>05
Sub-pages
Views that are pages of their own, each a route: TabNav, links drawn as tabs.
import { TabNav, TabNavLink } from "@qeetrix/react";
<TabNav aria-label="Users">
<TabNavLink render={<RouterLink to="/users" />}>All users</TabNavLink>
<TabNavLink render={<RouterLink to="/users/invitations" />} badge={12}>Invitations</TabNavLink>
</TabNav>06
Under a page header
PageHeader takes a TabsList in tabs; wrap the header and the panels in one Tabs.
import { PageContent, PageHeader } from "@qeetrix/react/experimental";
<Tabs defaultValue="users">
<PageHeader title="Payroll portal" tabs={<TabsList aria-label="Payroll portal">…</TabsList>} />
<PageContent>
<TabsPanel value="users">…</TabsPanel>
</PageContent>
</Tabs>