Tabs
Tab bar with keyboard navigation, closable tabs, and three visual variants (default, pills, underline). Supports horizontal/vertical orientation and panel rendering via snippets.
import { Tabs } from "phoundry-ui";Default Variant
Loading interactive example…
View source
<script lang="ts"> import { Tabs } from "phoundry-ui"; import type { TabItem } from "phoundry-ui";
let activeDefault = $state("general");
const basicTabs: TabItem[] = [ { id: "general", label: "General" }, { id: "appearance", label: "Appearance" }, { id: "keybindings", label: "Keybindings" }, { id: "disabled", label: "Disabled", disabled: true }, ];</script>
<Tabs items={basicTabs} value={activeDefault} onchange={(id: string) => { activeDefault = id; }}/><p class="mt-2 text-xs text-txt-tertiary">Active: {activeDefault}</p>Pills Variant
Loading interactive example…
View source
<script lang="ts"> import { Tabs } from "phoundry-ui"; import type { TabItem } from "phoundry-ui";
let activePills = $state("general");
const basicTabs: TabItem[] = [ { id: "general", label: "General" }, { id: "appearance", label: "Appearance" }, { id: "keybindings", label: "Keybindings" }, { id: "disabled", label: "Disabled", disabled: true }, ];</script>
<Tabs items={basicTabs} value={activePills} onchange={(id: string) => { activePills = id; }} variant="pills"/><p class="mt-2 text-xs text-txt-tertiary">Active: {activePills}</p>Vertical tab list
Loading interactive example…
View source
<script lang="ts"> import { Tabs } from "phoundry-ui"; import type { TabItem } from "phoundry-ui";
let verticalTab = $state("general");
const basicTabs: TabItem[] = [ { id: "general", label: "General" }, { id: "appearance", label: "Appearance" }, { id: "keybindings", label: "Keybindings" }, { id: "disabled", label: "Disabled", disabled: true }, ];</script>
<p class="mb-2 text-xs text-txt-secondary"> <code>orientation="vertical"</code> stacks tabs and pins the panel beside/below depending on your layout wrapper- Combine with <code>variant="pills"</code> for sidebar navigation.</p><div class="min-h-[12rem] rounded-lg border border-border-muted p-2"> <Tabs items={basicTabs} value={verticalTab} onchange={(id: string) => { verticalTab = id; }} orientation="vertical" variant="pills" class="max-h-48 min-h-0" > {#snippet panel(item)} <div class="rounded-lg bg-surface-sunken/40 p-4 text-xs text-txt-secondary" > Vertical orientation keeps the tablist beside the panel - active: <strong class="text-txt-primary">{item.label}</strong > </div> {/snippet} </Tabs></div>Underline Variant
Loading interactive example…
View source
<script lang="ts"> import { Tabs } from "phoundry-ui"; import type { TabItem } from "phoundry-ui";
let activeUnderline = $state("general");
const basicTabs: TabItem[] = [ { id: "general", label: "General" }, { id: "appearance", label: "Appearance" }, { id: "keybindings", label: "Keybindings" }, { id: "disabled", label: "Disabled", disabled: true }, ];</script>
<Tabs items={basicTabs} value={activeUnderline} onchange={(id: string) => { activeUnderline = id; }} variant="underline"/><p class="mt-2 text-xs text-txt-tertiary">Active: {activeUnderline}</p>Panel without View Transitions
Loading interactive example…
View source
<script lang="ts"> import { Tabs } from "phoundry-ui"; import type { TabItem } from "phoundry-ui";
let activePanel = $state("editor");
let noVtTab = $state("editor");
const closableTabs: TabItem[] = [ { id: "editor", label: "Editor", icon: "carbon:document" }, { id: "preview", label: "Preview", icon: "carbon:view", closable: true }, { id: "terminal", label: "Terminal", icon: "carbon:terminal", closable: true, }, ];
let panelTabs = $state([...closableTabs]);
function closeTab(id: string) { panelTabs = panelTabs.filter((t) => t.id !== id); if (activePanel === id) { activePanel = panelTabs[0]?.id ?? ""; } }</script>
<p class="mb-2 text-xs text-txt-secondary"> Disable cross-fading when the DOM inside panels cannot be duplicated safely or when animations feel sluggish on low-power devices.</p><Tabs items={panelTabs} value={noVtTab} onchange={(id: string) => { noVtTab = id; }} onclose={closeTab} viewTransition={false}> {#snippet panel(item)} <div class="rounded-lg border border-border-muted p-4 text-xs text-txt-secondary" > Static swap (no view transition)- <strong>{item.label}</strong> </div> {/snippet}</Tabs>With Panel Content
Loading interactive example…
View source
<script lang="ts"> import { Tabs } from "phoundry-ui"; import type { TabItem } from "phoundry-ui";
let activePanel = $state("editor");
const closableTabs: TabItem[] = [ { id: "editor", label: "Editor", icon: "carbon:document" }, { id: "preview", label: "Preview", icon: "carbon:view", closable: true }, { id: "terminal", label: "Terminal", icon: "carbon:terminal", closable: true, }, ];
let panelTabs = $state([...closableTabs]);
function closeTab(id: string) { panelTabs = panelTabs.filter((t) => t.id !== id); if (activePanel === id) { activePanel = panelTabs[0]?.id ?? ""; } }</script>
<Tabs items={panelTabs} value={activePanel} onchange={(id: string) => { activePanel = id; }} onclose={closeTab}> {#snippet panel(item)} <div class="rounded-lg border border-border-muted p-4 text-xs text-txt-secondary" > Content for <strong>{item.label}</strong> tab. </div> {/snippet}</Tabs>API
From phoundry-ui@0.4.21
| Name | Type | Default | Description |
|---|---|---|---|
itemsrequired | TabItem[] | — | Array of tab definitions. |
valuerequired | string | — | Active tab id. |
onchangerequired | (id: string) => void | — | Called when active tab changes. |
onclose | (id: string) => void | — | Called when a closable tab is closed. |
orientation | "horizontal" | "vertical" | 'horizontal' | Tab list direction. |
variant | "underline" | "default" | "pills" | 'default' | Visual style. |
size | "sm" | "md" | 'sm' | Tab trigger height aligned to Button sm (1.5rem) / md (1.75rem). |
viewTransition | boolean | true | Use the View Transition API to cross-fade panel content on tab change (where supported). |
class | string | '' | Additional CSS classes on the tab list. |
tab | Snippet<[item: TabItem, isActive: boolean]> | — | Custom tab renderer snippet. |
panel | Snippet<[item: TabItem]> | — | Panel content rendered below the active tab. |
TabItem
From phoundry-ui@0.4.21
| Name | Type | Default | Description |
|---|---|---|---|
idrequired | string | — | Unique tab identifier. |
labelrequired | string | — | Tab display text. |
icon | string | — | Iconify icon string. |
closable | boolean | — | Show close button on tab. |
disabled | boolean | — | Disable tab interaction. |
Usage tips
- Arrow keys navigate between tabs; Home/End jump to first/last.
- Use
variant="underline"for content-area tab bars and"pills"for sidebar navigation. - The
panelsnippet receives the activeTabItem- render different content per tab inside it. - Provide
oncloseto enable the close button on tabs markedclosable: true. - Panel content has built-in top padding and cross-fades via the View Transition API. Pass
viewTransition={false}to opt out.
CSS styling
.ph-tabs is the stable identification hook for Tabs. Part selectors and --_ph-* properties are internal. Component CSS is scoped and unlayered; Consumer classes remain additive and utility overrides may lose precedence.
Consumer class values still target the tab list. Sizes select --ph-comp-h-sm and --ph-comp-h-md (1.5rem and 1.75rem); the former sm height was 1.375rem. Variant, size, and orientation are independent attributes. Selected tabs use aria-selected.
Keep the shared component stylesheet and a named Theme imported. Decorative motion respects reduced-motion preferences.