Todae

Todae

Tabs

Panels that share one place on the page, one shown at a time. Tabs.Root owns the selected value. Tabs.List is the role="tablist"; each Tabs.Tab is a native button with role="tab", and each Tabs.Panel is a role="tabpanel" labelled by its tab. A tab and a panel pair by value.

On this page

The list holds one tab stop, on the selected tab. Arrow keys, Home and End move between tabs through useRovingFocus. Left and Right swap in a right-to-left page. A disabled tab is a native disabled button, so arrow keys skip it.

import { Tabs, Text } from '@tounsoo/todae';

export default function TabsBasic() {
  return (
    <Tabs.Root defaultValue="account">
      <Tabs.List aria-label="Settings">
        <Tabs.Tab value="account">Account</Tabs.Tab>
        <Tabs.Tab value="billing">Billing</Tabs.Tab>
        <Tabs.Tab value="audit" disabled>
          Audit log
        </Tabs.Tab>
        <Tabs.Tab value="team">Team</Tabs.Tab>
      </Tabs.List>
      <Tabs.Panel value="account">
        <Text.Root>Name, email and password.</Text.Root>
      </Tabs.Panel>
      <Tabs.Panel value="billing">
        <Text.Root>Plan, invoices and payment method.</Text.Root>
      </Tabs.Panel>
      <Tabs.Panel value="audit">
        <Text.Root>Sign-ins and changes, for admins.</Text.Root>
      </Tabs.Panel>
      <Tabs.Panel value="team">
        <Text.Root>Members and roles.</Text.Root>
      </Tabs.Panel>
    </Tabs.Root>
  );
}

Name, email and password.

The indicator slides from the old tab to the new one over tabs.motion.duration, in Chrome. In Safari and Firefox, in a right-to-left list that scrolls, and when the user prefers reduced motion, it moves at once.

Panels swap at once. A brand can fade the new panel in with tabs.motion.panel.duration (0ms by default) on tabs.motion.easing. The fade is opacity alone, the old panel goes at once so the two never overlap, and it keeps fading under reduced motion, since nothing moves.

A horizontal list that holds more tabs than fit scrolls sideways, in one row. An arrow shows at each edge where tabs are cut off; resting a mouse or pen on it scrolls that way. The arrows are for the pointer only: touch, a wheel and the arrow keys scroll the list as before, a tab that takes focus scrolls clear of them, and assistive technology never meets them. Pass arrows={false} to leave them out. A selected tab past the edge scrolls into view: on the first render, when your code picks it, and once a list that was hidden shows. Another control in the list, such as an add button, draws its focus ring inside itself, as the tabs do. A vertical list doesn't scroll.

activation="automatic" (default) selects a tab as soon as focus moves to it from another tab. Focus entering the list from outside selects nothing, even when it lands on a fallback tab because the selected one is disabled. Use activation="manual" when a panel is slow to render: arrow keys only move focus, and Enter, Space or a click selects. When focus leaves the list, its tab stop returns to the selected tab. orientation="vertical" puts the list beside the panels and moves with Up and Down.

The root takes value with onValueChange, or defaultValue. One tab is always selected, so there is no empty state. Only the selected panel renders its children; pass keepMounted to keep a hidden panel's state, such as a half-filled form. A panel is a Tab stop by default, so a screen reader user reaches its text; pass tabIndex={-1} when the panel starts with a control of its own.

import { Stack, Tabs, Text } from '@tounsoo/todae';
import { useState } from 'react';

export default function TabsManualVertical() {
  const [value, setValue] = useState('overview');
  return (
    <Stack.Root>
      <Tabs.Root value={value} onValueChange={setValue} orientation="vertical" activation="manual">
        <Tabs.List aria-label="Report">
          <Tabs.Tab value="overview">Overview</Tabs.Tab>
          <Tabs.Tab value="traffic">Traffic</Tabs.Tab>
          <Tabs.Tab value="errors">Errors</Tabs.Tab>
        </Tabs.List>
        <Tabs.Panel value="overview">
          <Text.Root>Arrow keys move focus. Enter or Space shows the panel.</Text.Root>
        </Tabs.Panel>
        <Tabs.Panel value="traffic">
          <Text.Root>Requests per minute.</Text.Root>
        </Tabs.Panel>
        <Tabs.Panel value="errors">
          <Text.Root>Failed requests.</Text.Root>
        </Tabs.Panel>
      </Tabs.Root>
      <Text.Root tone="muted">
        Selected: {value}
      </Text.Root>
    </Stack.Root>
  );
}

Arrow keys move focus. Enter or Space shows the panel.

Selected: overview

There is no native tabs element. An exclusive <details name> group looks similar but has no tab semantics or arrow keys, so it is an accordion, not tabs.

Accessible composition

Todae handles: Tabs.List is the role="tablist" with aria-orientation. Each Tabs.Tab is a button with role="tab", aria-selected and aria-controls, and each Tabs.Panel is a role="tabpanel" whose aria-labelledby points at its tab. Todae makes the ids that pair them, so neither part takes an id. It keeps at most one tab stop in the list, makes each panel a Tab stop by default, and hides unselected panels with hidden, even against a display in your own class.

You supply: A name for the list: aria-label, or aria-labelledby pointing at a visible heading. The type does not require one. Tab text that names its panel, since the panel takes its name from the tab; an icon-only tab needs aria-label. One Tabs.Panel for each Tabs.Tab, with the same value.

Watch for: A panel whose value matches no tab: its aria-labelledby points at an id that does not exist. A disabled tab is skipped by the arrow keys, so a reason it is unavailable needs to show somewhere else. A selected tab marked by color alone after restyling.

When to use

When: Switch between sibling views of the same object in one place, such as settings sections or report views, where one view shows at a time.

When not: Moving to another page → links. A list of actions → Menu. Several sections open at once, or long content read top to bottom → headings or <details>.

Props

Tabs.Root props
NameTypeDescription
valuestring

Controlled selected tab. Pass with onValueChange.

defaultValuestring

Initial selected tab when uncontrolled.

onValueChange(value: string) => void

Fires with the next selected tab.

orientation"horizontal" | "vertical"

Arrow keys, layout and aria-orientation.

Default: "horizontal"

activation"automatic" | "manual"

automatic selects on focus. manual waits for Enter, Space or a click.

Default: "automatic"

childrenReact.ReactNode

Tabs.List and Tabs.Panel.

classNamestring

Optional class on the root.

Tabs.List props
NameTypeDescription
arrowsboolean

Whether a horizontal list shows an arrow at each edge where tabs are cut off, while there is more to scroll that way. Resting a mouse or pen on one scrolls toward it. The arrows are for the pointer only: touch, a wheel and the arrow keys scroll the list as before, and assistive technology never meets them. A vertical list never scrolls, so it shows none.

Default: true

aria-labelstring

Names the tablist when no visible caption exists.

aria-labelledbystring

Id of a visible caption for the tablist.

childrenReact.ReactNode

Tabs.Tab children.

classNamestring

Optional class on the tablist.

Tabs.Tab props
NameTypeDescription
value Requiredstring

Matches a Tabs.Panel value.

disabledboolean

Native disabled. Skipped by arrow keys.

childrenReact.ReactNode

Tab label.

classNamestring

Optional class on the tab.

Tabs.Panel props
NameTypeDescription
value Requiredstring

Matches a Tabs.Tab value.

keepMountedboolean

Keep children mounted while hidden, so their state survives a tab switch.

Default: false

childrenReact.ReactNode

Panel content.

classNamestring

Optional class on the panel.