Skip to main content
  1. Docs
  2. Components
  3. 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

tabs.tsx
// 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.

PropTypeDefaultWhat it does
Tabs: value · defaultValuestringthe first tabThe 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: activateOnFocusbooleantrueSelect as focus moves; off for slow panels, so Enter or Space selects.
Tab: valuestringrequiredMatches its TabsPanel's value.
Tab: icon · filledWhenSelectedIconSource · boolean— · trueA 16px leading icon, filled while selected; false keeps the outline. An icon with no filled drawing keeps its outline.
Tab: badgeReactNode—A number, formatted for the locale as a neutral Badge; or your own Badge.
Tab: disabledbooleanfalseCan't be selected; it stays reachable by the arrow keys, so it's read.
TabNavLink: current · icon · filledWhenSelectedboolean · IconSource · booleanfalse · — · trueIn a TabNav: aria-current="page" and the bar; an icon filled while current, as a Tab's.
TabsPanel: keepMountedbooleanfalseKeep a hidden panel in the page, so its state survives.

03

Parts

Each part carries a data-slot, for tests and placement.

data-slotElementWhat 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.

user-page.tsx
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.

users-layout.tsx
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.

application-page.tsx
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>
Next — TabsAccessibility