Tabs

Layered panels with one visible at a time. The classes know nothing about any component library. The classless build has a Kobalte layer that binds its state attributes to these same classes.

alpha The class names and states here are stable. The look is not: these styles can change in a minor release, without a major version bump.

ClassDoes what
tabsThe tab list: a row with a bottom rule
tabA tab item. Works on a button, an anchor or a label
tab-activeThe selected tab: darker, bold, underlined
tab-disabledA disabled tab: greyed out and inert
tab-contentA tab panel

Basic

On the class-based build you mark the selected tab and wire the clicks. Kobalte sets data-selected, data-disabled and data-orientation itself but never adds tab-active, so /classless/kobalte binds those attributes to the same classes and its markup needs none of them.

<div>
  <div class="tabs" role="tablist">
    <button class="tab tab-active" role="tab" id="t-profile" aria-controls="p-profile" data-selected>Profile</button>
    <button class="tab" role="tab" id="t-dashboard" aria-controls="p-dashboard">Dashboard</button>
    <button class="tab tab-disabled" role="tab" id="t-billing" aria-controls="p-billing">Billing</button>
  </div>
  <div class="tab-content" role="tabpanel" id="p-profile" aria-labelledby="t-profile">Profile details</div>
  <div class="tab-content" role="tabpanel" id="p-dashboard" aria-labelledby="t-dashboard" hidden>Dashboard details</div>
  <div class="tab-content" role="tabpanel" id="p-billing" aria-labelledby="t-billing" hidden>Upgrade to see billing</div>
</div>

Tabs.Indicator has no class of its own, so it lives in the Kobalte layer as .tab-indicator. When one is present the selected tab drops its own underline, so you never get both.

Importing the Kobalte layer

// instead of "pkg:@sparkstone/css/classless"
@use "pkg:@sparkstone/css/classless/kobalte";

Vertical

data-orientation="vertical" turns the list into a column and moves the indicator to the trailing edge. This is Kobalte-only: the classes have no vertical variant.

<div style="display: flex; gap: 1rem">
  <div role="tablist" data-orientation="vertical">
    <button role="tab" id="v-general" aria-controls="vp-general" data-selected>General</button>
    <button role="tab" id="v-members" aria-controls="vp-members">Members</button>
    <div class="tab-indicator" data-orientation="vertical"></div>
  </div>
  <div role="tabpanel" id="vp-general" aria-labelledby="v-general">General settings</div>
  <div role="tabpanel" id="vp-members" aria-labelledby="v-members" hidden>Member settings</div>
</div>

On the class-based build

There is no Kobalte layer for the class-based build, and it does not need one: put the classes on the Kobalte parts yourself. Both paths apply the same declarations, so the two approaches produce identical styles and can be mixed.

const [tab, setTab] = createSignal("week");

<Tabs value={tab()} onChange={setTab}>
  <Tabs.List class="tabs">
    <Tabs.Trigger
      class="tab"
      classList={{ "tab-active": tab() === "week" }}
      value="week"
    >
      This week
    </Tabs.Trigger>
  </Tabs.List>
</Tabs>

Composition

Common ways to put this together with other components. The general rules are on Composition.

Tabs over a card

Tabs switch what one card shows. The tab row sits on the page and the panel holds prose.

Same markup in both builds
<div>
  <div class="tabs" role="tablist">
    <button class="tab tab-active" role="tab" id="ct-overview" aria-controls="cp-overview" data-selected>Overview</button>
    <button class="tab" role="tab" id="ct-pricing" aria-controls="cp-pricing">Pricing</button>
    <button class="tab" role="tab" id="ct-faq" aria-controls="cp-faq">Questions</button>
  </div>
  <div class="tab-content prose" role="tabpanel" id="cp-overview" aria-labelledby="ct-overview">
    <p>What the service is and who it is for.</p>
    <a href="#" class="btn">Get started</a>
  </div>
  <div class="tab-content prose" role="tabpanel" id="cp-pricing" aria-labelledby="ct-pricing" hidden>
    <p>A monthly retainer, scoped in writing before anything is built.</p>
  </div>
  <div class="tab-content prose" role="tabpanel" id="cp-faq" aria-labelledby="ct-faq" hidden>
    <p>Answers to the questions people ask first.</p>
  </div>
</div>

Tabs inside a card

A card whose content splits into views. The tab row runs across the top of the card.

Same markup in both builds
<article class="card">
  <div class="tabs" role="tablist">
    <button class="tab tab-active" role="tab" id="ct2-details" aria-controls="cp2-details" data-selected>Details</button>
    <button class="tab" role="tab" id="ct2-access" aria-controls="cp2-access">Access</button>
  </div>
  <div class="tab-content" role="tabpanel" id="cp2-details" aria-labelledby="ct2-details">
    <label class="label"><p>Project name</p><input class="input" value="Website" /></label>
  </div>
  <div class="tab-content" role="tabpanel" id="cp2-access" aria-labelledby="ct2-access" hidden>
    <label class="label"><input type="checkbox" class="checkbox" checked /> Anyone with the link can view</label>
  </div>
  <footer class="card-actions flex" style="justify-content: end">
    <button class="btn">Save</button>
  </footer>
</article>