oakoss/ui
Components

Tabs

Panels of content shown one at a time, chosen from a row of tabs.

SourceReact Aria
Change your name, photo and email.

Installation

npx shadcn@latest add @oakoss/tabs

Usage

import {
  Tabs,
  TabsContent,
  TabsList,
  TabsTrigger,
} from '#/components/ui/navigation/tabs';

<Tabs>
  <TabsList aria-label="Account">
    <TabsTrigger id="profile">Profile</TabsTrigger>
    <TabsTrigger id="billing">Billing</TabsTrigger>
  </TabsList>
  <TabsContent id="profile">Your name and photo.</TabsContent>
  <TabsContent id="billing">Your card and invoices.</TabsContent>
</Tabs>;

Each TabsContent shares its id with a TabsTrigger.

Examples

Line

variant="line" marks the selected tab with a line under it instead of a filled chip. The line slides to the tab selected and sizes to it, or jumps there when the visitor prefers reduced motion. To restyle it, target its slot from the tab, as in className="[&_[data-slot=tabs-indicator]]:border-primary".

A summary of the project.

Vertical

orientation="vertical" stacks the tabs beside the panel. In the line look, the line runs along the side facing the panel, on the right or, right to left, the left.

Language and time zone.

Accessibility

React Aria renders a tablist of tabs, each linked to its tabpanel, and the selected tab is the list's one Tab stop. Name the list with aria-label or aria-labelledby; the type doesn't require it, since a visible heading often names the section instead.

This component adds:

  • Selected state: in Windows High Contrast the default look's selected tab takes the system's selection colors, and the line look's line is a border, which the mode keeps. The line is decorative: hidden from assistive technology, and never focused. The selected tab opts out of the text backplate the mode draws, which would hide its label. A disabled tab takes the system's disabled color, selected or not.
  • Focus: tabs show the focus outline. A panel with nothing focusable inside is a Tab stop, so it shows the outline too, drawn inside its edge.
  • Target size: tabs sit close together, so they don't grow to 44px; each is at least 24px tall.
KeyAction
TabMoves into the selected tab, then into the panel
ArrowLeft / ArrowRightMoves between tabs in either orientation; reversed right to left
ArrowUp / ArrowDownMoves between tabs when vertical
Home / EndMoves to the first or last tab
Space / EnterSelects the focused tab, when keyboardActivation="manual"

Arrow keys select the tab they move to; with keyboardActivation="manual" they only move focus. Follows the WAI-ARIA tabs pattern.

API

Tabs

Extends React Aria's Tabs, and sets the look for its list and tabs.

Props

Prop

Type

Also accepts all React Aria Tabs props.

Data attributes

AttributePresent when
data-slotAlways tabs
data-variantAlways; default or line
data-orientationAlways; horizontal or vertical
data-disabledisDisabled is set
data-focus-visibleSomething inside has keyboard focus

TabsList

Extends React Aria's TabList, and accepts all its props.

Data attributes

AttributePresent when
data-slotAlways tabs-list
data-variantAlways; the look from Tabs
data-orientationAlways; horizontal or vertical

TabsTrigger

Extends React Aria's Tab, and accepts all its props. Its id is the key selectedKey refers to.

Data attributes

AttributePresent when
data-slotAlways tabs-trigger
data-selectedIt's selected
data-hoveredA pointer hovers it
data-pressedIt's being pressed
data-focus-visibleIt has keyboard focus
data-disabledIt's disabled

In the line look, the selected tab holds the line, an element with data-slot="tabs-indicator".

TabsContent

Extends React Aria's TabPanel, and accepts all its props.

Data attributes

AttributePresent when
data-slotAlways tabs-content
data-focus-visibleIt has keyboard focus
data-inertIts tab isn't selected, while it's kept by shouldForceMount or exiting
data-enteringIt's appearing
data-exitingIt's leaving