Tabs
A tablist and its panels. It is a compound family that wraps the @magic-spells/tab-group web component, so the roving tabindex, the arrow/Home/End keyboard model, the disabled-tab skipping, panel visibility and every role, id and aria attribute come from the component rather than from a hand-rolled copy in this file.
Installation
Copy the family into your app:
puzzle add piece tabs
It has one runtime dependency — the web component it wraps:
npm install @magic-spells/tab-group
Then merge its stylesheet into your app's style entry. It is required, and for one rule above all: tab-panel[hidden] is what actually hides an inactive panel. Without it every panel renders at once.
/* app/styles/styles.css */ @import "tailwindcss"; @import "@magic-spells/tab-group/css" layer(components); /* required */
Requires the pieces.css tokens merged into your app styles (see Introduction).
Usage
import Tabs from '@/components/ui/Tabs';
<Tabs value={ tab } @change={ setTab }>
<Tabs.List>
<Tabs.Tab value="account">Account</Tabs.Tab>
<Tabs.Tab value="password">Password</Tabs.Tab>
</Tabs.List>
<Tabs.Panel value="account">…real markup…</Tabs.Panel>
<Tabs.Panel value="password">…real markup…</Tabs.Panel>
</Tabs>Tabs and panels pair by position, not by value: upstream matches the nth tab-button to the nth tab-panel. Render one panel per tab in the same order — the root warns in the console if the two sequences diverge. If both come from a loop, drive both from the same array so the counts can never disagree mid-patch.
Pill variant
Disabled tab
Controlled value
Focus this input first, then press the button: activating a tab programmatically never moves focus, so the caret stays here.
Tabs from a loop
Nested tabs
Reference
Tabs
valueControlled: the active tab’s value string. Edge-triggered, and re-applied when the tab set changes.defaultValueUncontrolled seed, applied once at mount — before the upgrade, so the first paint has no flash.variant'underline' (default) | 'pills' | 'buttons'. Stamped as data-variant for the members to read.classMerged onto the tab-group host. A gap-* here replaces the default 16px list-to-panel gap.@change(value)Value-first, once per activation. A nested group’s bubbling tabchange is filtered out by target.Tabs.List
classMerged onto tab-list, after the chrome. Must be a direct child of Tabs, with the tabs as its direct children.Tabs.Tab
valueRequired. Carried as data-value; the root maps it to the index upstream works in.disabledNot clickable and skipped by arrow-key roving. Driving `value` to a disabled tab is refused, with a console warning.classMerged onto tab-button, after the chrome. The selected look hangs off the component’s own aria-selected.Tabs.Panel
valueRequired, and must match the Tabs.Tab at the same position — upstream pairs them positionally.classRendered on tab-panel. Never a display utility: it would outrank tab-panel[hidden] and leave every panel visible.The variant is stamped as data-variant on the root and read by the members through a descendant selector, because Puzzle has no cross-component context to pass it down as a prop. One consequence: a nested Tabs with a different variant collides, since the match has equal specificity at both depths. Give the inner members their own class with the ! suffix (gap-4!) to escape it.