Skip to Content
CodeUI

Tabs

@codeui/solid v0.3.0

Named panels that share one content area.

When to use

Use Tabs to switch between related panels, such as a snippet's code and settings.

When to choose another component

Use SegmentedControl to choose a compact setting such as an export format or preview mode. Tabs associates each trigger with a content panel. SegmentedControl represents a setting value and does not require a panel for each choice.

Live demo

Your TypeScript snippet.
tabs/basic.tsx
import { Tabs, TabsList, TabsHeader, TabsContent } from "@codeui/solid";
export default function Example() {
	return <Tabs defaultValue="code" >
		<TabsList aria-label="Snippet details"><TabsHeader value="code">Code</TabsHeader><TabsHeader value="settings">Settings</TabsHeader><TabsHeader value="history" disabled>History</TabsHeader></TabsList>
		<TabsContent value="code">Your TypeScript snippet.</TabsContent><TabsContent value="settings">Font, theme, and export settings.</TabsContent><TabsContent value="history">Revision history.</TabsContent>
	</Tabs>;
}

Each header's value matches a content panel's value. Give TabsList an accessible label.

Anatomy

Your TypeScript snippet.

Tap a part to outline it in the demo.

  1. 01Tabstabs
ExportRendersclasses keydata-cuiRole
TabsdivnonetabsRoot container
TabsListdivnonenonetablist
TabsHeaderbuttonnonenonetab
TabsContentdivnonenonetabpanel
Internal indicatordivnonenoneVisual indicator

Each public part merges its class with kit styles. Tabs has no classes map. Only the root has a kit data-cui attribute. Kobalte supplies state and orientation attributes on its parts.

Variants

Inline indicator

Your TypeScript snippet.
tabs/inline.tsx
import { Tabs, TabsList, TabsHeader, TabsContent } from "@codeui/solid";
export default function Example() {
	return <Tabs defaultValue="code" variant="inline">
		<TabsList aria-label="Snippet details"><TabsHeader value="code">Code</TabsHeader><TabsHeader value="settings">Settings</TabsHeader><TabsHeader value="history" disabled>History</TabsHeader></TabsList>
		<TabsContent value="code">Your TypeScript snippet.</TabsContent><TabsContent value="settings">Font, theme, and export settings.</TabsContent><TabsContent value="history">Revision history.</TabsContent>
	</Tabs>;
}

variant="inline" makes TabsList insert an indicator aligned with the selected header. The default variant has no indicator. The variant does not change panel behavior. Import Indicator from @codeui/solid/tabs/parts to place it explicitly.

Vertical orientation

Your TypeScript snippet.
tabs/vertical.tsx
import { Tabs, TabsList, TabsHeader, TabsContent } from "@codeui/solid";
export default function Example() {
	return <Tabs defaultValue="code" variant="inline" orientation="vertical">
		<TabsList aria-label="Snippet details"><TabsHeader value="code">Code</TabsHeader><TabsHeader value="settings">Settings</TabsHeader><TabsHeader value="history" disabled>History</TabsHeader></TabsList>
		<TabsContent value="code">Your TypeScript snippet.</TabsContent><TabsContent value="settings">Font, theme, and export settings.</TabsContent><TabsContent value="history">Revision history.</TabsContent>
	</Tabs>;
}

orientation="vertical" puts headers in a column and panels beside them. It also changes the navigation keys to Up Arrow and Down Arrow.

States

Disabled and manual activation

Your TypeScript snippet.
tabs/manual.tsx
import { Tabs, TabsList, TabsHeader, TabsContent } from "@codeui/solid";
export default function Example() {
	return <Tabs defaultValue="code" activationMode="manual">
		<TabsList aria-label="Snippet details"><TabsHeader value="code">Code</TabsHeader><TabsHeader value="settings">Settings</TabsHeader><TabsHeader value="history" disabled>History</TabsHeader></TabsList>
		<TabsContent value="code">Your TypeScript snippet.</TabsContent><TabsContent value="settings">Font, theme, and export settings.</TabsContent><TabsContent value="history">Revision history.</TabsContent>
	</Tabs>;
}

A disabled header cannot receive keyboard focus or activate its panel. The default activation mode selects a tab when it receives focus. activationMode="manual" keeps selection unchanged until Enter or Space. Use manual activation when selecting a panel starts expensive work.

Ready API

Tabs

Renders the root and shares selection with its children.

Prop

Type

Prop

Type

TabsList

Renders the tablist and the inline variant's indicator.

Prop

Type

TabsHeader

Renders a trigger button with a panel value.

Prop

Type

Prop

Type

TabsContent

Renders the selected panel. forceMount keeps inactive content mounted when you need to manage its visibility.

Prop

Type

Prop

Type

Other behavior follows the Kobalte Tabs contract. The package root exports the four components, but does not re-export their props types.

Styled parts API

Import Root, List, Trigger, Content, and Indicator from @codeui/solid/tabs/parts. Put each trigger in List and match its value to a panel. Add Indicator inside List when you want the inline treatment.

import * as T from "@codeui/solid/tabs/parts";

<T.Root defaultValue="preview" variant="inline">
	<T.List aria-label="Editor views">
		<T.Trigger value="preview">Preview</T.Trigger>
		<T.Trigger value="source">Source</T.Trigger>
		<T.Indicator />
	</T.List>
	<T.Content value="preview">Preview content</T.Content>
	<T.Content value="source">Source content</T.Content>
</T.Root>

List uses the children you supply. The ready TabsList adds an indicator for the inline variant.

Accessibility

Keyboard

KeyAction
TabEnters the selected tab, then moves into the panel or next focusable element.
Left Arrow, Right ArrowMoves between enabled horizontal tabs.
Up Arrow, Down ArrowMoves between enabled vertical tabs.
Home, EndMoves to the first or last enabled tab.
Enter, SpaceActivates a focused tab in manual mode.

ARIA

TabsList has role="tablist" and aria-orientation. Headers have role="tab", aria-selected, and aria-controls. Panels have role="tabpanel" and aria-labelledby linked to their header. Disabled headers expose aria-disabled.

Focus

Arrow navigation keeps focus on the headers. Activating a tab does not move focus into its panel. There is no open or close cycle. When removing a selected dynamic tab, choose a remaining value before removing its header.

SSR notes

The root, list, headers, and initially selected panel render on the server. Inactive panels mount when selected unless forceMount is set. Indicator geometry is measured on the client. Keep initial values and tab IDs stable for hydration. There is no portal.

Theming hooks

Tabs reads --cui-border-divider, --cui-border-width, --cui-action-neutral-hover, --cui-text-muted, --cui-text-default, and --cui-accent-selection. Text and spacing use --cui-font-size-sm, --cui-font-weight-semibold, --cui-space-2, and --cui-space-4. Transitions use --cui-motion-duration-normal and --cui-motion-duration-fast with --cui-motion-ease-out. The current kit draws a line below or beside the tablist, which predates Inkstone's line rule. The inline indicator slides in 160ms when you click a tab; arrow keys move it instantly (Inkstone §7.1), and reduced motion never slides it. A focused header shows the 2px --cui-focus-color ring on :focus-visible. Header text sets --cui-font-line-height-sm.

Composition examples

Dynamic snippet tabs

Editing Fetch with retries
tabs/dynamic.tsx
import { Button, Tabs, TabsList, TabsHeader, TabsContent } from "@codeui/solid";
import { createSignal, For } from "solid-js";
export default function Dynamic() {
	const [tabs, setTabs] = createSignal([{ id: "snippet-1", title: "Fetch with retries" }]);
	const [value, setValue] = createSignal("snippet-1");
	let nextId = 2;
	function add() {
		const id = `snippet-${nextId++}`;
		setTabs(previous => [...previous, { id, title: `Untitled snippet ${nextId - 1}` }]);
		setValue(id);
	}
	function remove() {
		const remaining = tabs().filter(tab => tab.id !== value());
		const next = remaining[0];
		if (next) { setValue(next.id); setTabs(remaining); }
	}
	return <div><Button variant="secondary" onClick={add}>Add snippet</Button><Button variant="secondary" disabled={tabs().length === 1} onClick={remove}>Close selected</Button>
		<Tabs variant="inline" value={value()} onChange={setValue} class="snippet-tabs"><TabsList aria-label="Open snippets"><For each={tabs()}>{tab => <TabsHeader value={tab.id}>{tab.title}</TabsHeader>}</For></TabsList><For each={tabs()}>{tab => <TabsContent value={tab.id}>Editing {tab.title}</TabsContent>}</For></Tabs>
	</div>;
}

Stable IDs pair each header with its panel. Adding a snippet selects it. Closing the selected snippet chooses the first remaining snippet. The final tab cannot close. The controlled value keeps selection valid when the collection changes.

On this page