PeakUI

Tabs

Tabbed sections with a scrolling tab list

Usage

import {Tabs} from "@peakui/react";

Anatomy

import {Tabs} from "@peakui/react";

export default () => (
  <Tabs>
    <Tabs.ListContainer>
      <Tabs.List aria-label="Sections">
        <Tabs.Tab id="overview">
          Overview
          <Tabs.Indicator />
        </Tabs.Tab>
      </Tabs.List>
    </Tabs.ListContainer>
    <Tabs.Panel id="overview">Overview content</Tabs.Panel>
  </Tabs>
);

Examples

Vertical Orientation

orientation="vertical" lays the list out as a column beside the panels.

Overflow Scrolling

Tabs.ListContainer wraps the list in a scroll area with chevron buttons that appear only when the list overflows.

Variants

variant="secondary" renders an underline indicator instead of the pill.

With Separator

Place Tabs.Separator inside a tab to divide it from its neighbour.

Disabled State

isDisabled on a tab removes it from selection and keyboard focus order.

Default Selected

defaultSelectedKey picks the initially selected tab.

Controlled Selection

selectedKey with onSelectionChange controls the selection from state.

Customization

Tailwind CSS

<Tabs.List className="w-fit *:h-6 *:px-3" aria-label="Sections">
  <Tabs.Tab id="daily">
    Daily
    <Tabs.Indicator className="bg-accent" />
  </Tabs.Tab>
</Tabs.List>

Global CSS

@layer components {
  .tabs__tab {
    font-weight: normal;
  }

  .tabs--secondary {
    --color-accent: var(--color-success);
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The Tabs component uses these CSS classes (view source styles):

Base Classes

  • .tabs - Base component styles: flex column in horizontal orientation, row in vertical

Element Classes

  • .tabs__list-container - The scroll container around the list: background, radius, chevron buttons
  • .tabs__list-container__scroller - The scrollable area between the chevrons
  • .tabs__list-container__scroll-prev - The backward scroll chevron button
  • .tabs__list-container__scroll-next - The forward scroll chevron button
  • .tabs__list - The tab list itself
  • .tabs__tab - A single tab
  • .tabs__indicator - The selection indicator rendered inside the selected tab
  • .tabs__separator - The divider between neighbouring tabs
  • .tabs__panel - A tab panel

Modifier Classes

  • .tabs--align-start - Tab content aligned to the start edge
  • .tabs--align-end - Tab content aligned to the end edge
  • .tabs--secondary - Underline variant: border on the container, line indicator

Slots

  • [data-slot="tabs"] - The root element
  • [data-slot="tabs-list-container"] - The scroll container around the list
  • [data-slot="tabs-list"] - The tab list
  • [data-slot="tabs-tab"] - A single tab
  • [data-slot="tabs-indicator"] - The selection indicator
  • [data-slot="tabs-separator"] - The divider between tabs
  • [data-slot="tabs-panel"] - A tab panel
  • [data-slot="tabs-scroll-prev"] - The backward scroll chevron button
  • [data-slot="tabs-scroll-next"] - The forward scroll chevron button

Interactive States

The component supports both CSS pseudo-classes and data attributes:

  • Hover: :hover or [data-hovered]
  • Pressed: :active or [data-pressed]
  • Focus: :focus-visible or [data-focus-visible]
  • Disabled: :disabled, [data-disabled] or [aria-disabled="true"]
  • Selected: [data-selected="true"]

API Reference

Tabs

PropTypeDefaultDescription
align"start" | "center" | "end""center"Alignment of the tab content
variant"primary" | "secondary""primary"Pill indicator or underline indicator
orientation"horizontal" | "vertical""horizontal"Layout of the list relative to the panels
selectedKeyKey | null-The currently selected tab id, controlled
defaultSelectedKeyKey-The initially selected tab id
onSelectionChange(key: Key) => void-Called when the selection changes
isDisabledboolean-Disables every tab
childrenReactNode-The list and panels
classNamestring-Additional classes for the root
...restReact Aria Tabs attributes-Focus, keyboard activation and DOM attributes of the underlying React Aria Tabs

Tabs.ListContainer

PropTypeDefaultDescription
childrenReactNode-The tab list
classNamestring-Additional classes for the container
renderDOMRenderFunction<"div", undefined>-Replaces the rendered <div> with your own element

Without it, Tabs.List stays a plain React Aria tab list with no scroll area or chevron buttons.

Tabs.List

PropTypeDefaultDescription
aria-labelstring-Accessible name of the tab list
childrenReactNode-The tabs
classNamestring-Additional classes for the list
...restReact Aria TabList attributes-Attributes of the underlying React Aria TabList

Tabs.Tab

PropTypeDefaultDescription
idKey-The tab id, matched with the panel id
isDisabledboolean-Removes the tab from selection and focus order
childrenReactNode-The tab label, usually with a Tabs.Indicator
classNamestring-Additional classes for the tab
...restReact Aria Tab attributes-Attributes of the underlying React Aria Tab

Tabs.Indicator

PropTypeDefaultDescription
classNamestring-Additional classes for the indicator
...restReact Aria SelectionIndicator attributes-Attributes of the underlying React Aria SelectionIndicator

Render it inside each tab; the indicator animates from the previously selected tab on change.

Tabs.Separator

PropTypeDefaultDescription
classNamestring-Additional classes for the separator
renderDOMRenderFunction<"span", undefined>-Replaces the rendered <span> with your own element

Hidden in the secondary variant and next to the selected tab.

Tabs.Panel

PropTypeDefaultDescription
idKey-The panel id, matched with the tab id
childrenReactNode-The panel content
classNamestring-Additional classes for the panel
...restReact Aria TabPanel attributes-Attributes of the underlying React Aria TabPanel

On this page