Navigation

Tabs

Root tabs composite that owns the active value and orientation and coordinates tab, tab-list, and tab-panel descendants via context.

import { Tabs } from '@lostgradient/cinder';
navigationtabs
01

Overview

Reference usage

Composite tabs root that coordinates tab list, tab triggers, and their content panels.

Usage

Tabs is a compound component. Import the parent once and compose its leaves via the namespace API: Tabs.List, Tabs.Trigger, and Tabs.Panel.

svelte
<script lang="ts">
  import { Tabs } from '@lostgradient/cinder';

  let active = $state('overview');
</script>

<Tabs bind:value={active}>
  <Tabs.List label="Project sections">
    <Tabs.Trigger value="overview">Overview</Tabs.Trigger>
    <Tabs.Trigger value="activity">Activity</Tabs.Trigger>
    <Tabs.Trigger value="settings">Settings</Tabs.Trigger>
  </Tabs.List>

  <Tabs.Panel value="overview">Project overview.</Tabs.Panel>
  <Tabs.Panel value="activity">Recent activity.</Tabs.Panel>
  <Tabs.Panel value="settings">Project settings.</Tabs.Panel>
</Tabs>

The leaves are also named exports of @lostgradient/cinder.

Narrow collapse

When a horizontal tab bar does not fit its container (collapseOnOverflow, on by default), it becomes one full-width select reading "Tab: Access", so a narrow pane shows a single control instead of a bar that scrolls sideways. The bar is measured as FilterBar measures its row, the width its tabs need against the width the container has, so three short tabs stay a bar on a phone and a set that overflows collapses at any viewport width. collapseBelow (a CSS length such as "640px", off by default) also collapses the bar below a viewport width, fit or not. Picking an option selects its tab. The tab bar is hidden, not removed, so every tab still registers and every panel keeps its name. Each option's label is the tab's own text (without its count pill, which becomes the option's note); pass label on a trigger when the text changes after the first render. collapseLabel words the select's name and the prefix before its value, and collapseBelow={false} keeps the bar at every width. Vertical tabs never collapse.

Caller-owned panels

Use Tabs.Panel for ordinary tabs where each trigger owns one rendered panel. When the selected value controls one stable external surface, pass that panel id through Tabs.Trigger's controls prop and render the panel yourself:

svelte
<script lang="ts">
  import { Tabs } from '@lostgradient/cinder';

  let active = $state('index.ts');
  const tabIds: Record<string, string> = {
    'index.ts': 'editor-tab-index',
    'app.svelte': 'editor-tab-app',
  };
</script>

<Tabs bind:value={active}>
  <Tabs.List label="Editor files">
    <Tabs.Trigger id={tabIds['index.ts']} value="index.ts" controls="editor-panel">
      index.ts
    </Tabs.Trigger>
    <Tabs.Trigger id={tabIds['app.svelte']} value="app.svelte" controls="editor-panel">
      app.svelte
    </Tabs.Trigger>
  </Tabs.List>
</Tabs>

<div id="editor-panel" role="tabpanel" aria-labelledby={tabIds[active]} tabindex="0">
  {active}
</div>

This keeps Cinder in charge of roving tabindex, activation, disabled state, and tab styling while the caller owns an imperative or stateful panel element. Give the tabs explicit ids so the external panel can label itself with the active tab.

Trailing badges and counts

Each Tabs.Trigger accepts a trailing snippet for badges, counts, or status dots. Render the library Badge inside it for idiomatic styling — there is no separate badge class to learn:

svelte
<script lang="ts">
  import { Badge } from '@lostgradient/cinder';
</script>

<Tabs.Trigger value="inbox">
  Inbox
  {#snippet trailing()}
    <Badge>3</Badge>
  {/snippet}
</Tabs.Trigger>

The trailing wrapper is aria-hidden, so its content is omitted from the tab's accessible name. Any count that carries meaning must therefore also live in the tab's visible children (the accessible name) — never rely on the trailing badge alone to convey it.

Live preview

Basic tabs

Cinder is a small but opinionated component library for Svelte 5.

02

When to use

Use when
  • Switching between several panels of related content under one heading area.
  • Building the WAI-ARIA tabs pattern with shared keyboard navigation and activation rules.
Avoid when
  • Picking one of two to five short values inline — use segmented-control instead.
  • Showing ordered progress through a wizard — use steps instead.
03

Examples

Basic tabs

Three tabs with associated panels; clicking a tab switches the panel. Uses the Tabs namespace API.

Fill pane tabs

Tabs can fill a bounded flex pane so the active panel takes the remaining height.

Narrow collapse to a select

A horizontal tab bar that does not fit its container becomes one full-width select reading "Tab: Access". The tabs stay mounted, hidden, so the panels keep their names. This example sets collapseBelow wide enough to show the select form at any width.

Vertical tabs with keyboard navigation

A vertical tablist: focus a tab and use ↑/↓ to move. The focus ring must render complete on all sides even though the tab list is a clipping (overflow) container.

Tabs with trailing badges

Tabs use a decorative `trailing` snippet (wrapped in aria-hidden) for badges and counters. The accessible name only includes the visible label.

Tabs with an attention count

A tab that holds something needing attention carries an amber count pill from `count`; a healthy tab (zero or no count) carries none. The count is part of the tab’s accessible name, so it never depends on colour.

Tabs with keyboard navigation

Focus a tab and use ←/→ to move; horizontal tablists activate on focus per the WAI-ARIA pattern.

04

Props

Props for tabs
Name
Type
Default
Description
value bindable text '' Bound active tab value.
onValueChangeRequest (next: string) => stringvoid Intercept a proposed tab value before the bindable value is written. Return a replacement value to transform it.
onValueChange (next: string) => void Notify after the bindable value has been committed.
orientation 'horizontal' | 'vertical' 'horizontal' Layout orientation. Affects which arrow keys move between tabs.
collapseOnOverflow boolean true Collapses a horizontal tab bar into a select reading "Tab: Access" when the bar does not fit its container, measured as FilterBar measures its row: the bar's content width against the width it has. Tabs that fit stay a bar at every width, so a phone with three short tabs keeps them. The tabs stay in the page, hidden, and the panels keep their names. Set false to keep a bar that scrolls sideways instead. Vertical tabs never collapse.
collapseBelow text false Viewport width below which a horizontal tab bar always collapses to the select, whether or not it fits. A simple CSS length such as '640px', or false for no viewport rule. Vertical tabs never collapse. Default false.
collapseLabel text 'Tab' The select's accessible name and the prefix before the current tab's label in its trigger. Default "Tab".
compactTouch boolean false Keep the collapsed selector's painted face compact while extending its touch target.
fill boolean false Fill the available space when Tabs is placed inside a bounded flex parent, letting the active TabPanel occupy the remaining height.
activateOnFocus boolean When true (default for horizontal), focusing a tab also activates it (the panel updates immediately). Vertical defaults to manual activation — the user moves focus with arrows, then presses Enter or Space.
children required snippet Tab and TabPanel children.