Searching Open Sourcery

Type to search Open Sourcery.

Inputs & Controls

Tab Group

Tab list and tab panel elements with roving focus and three ready-made skins.

v1.2.0@magic-spells/tab-group

$ npm i @magic-spells/tab-group

GitHubnpm

Live demo

OverviewSpecsShippingEach panel is ordinary markup in the page, so nothing is fetched or re-rendered when a tab changes.Arrow keys move between tabs, Home and End jump to the ends, and the ARIA wiring is the element’s own.A hidden panel is display:none from the package stylesheet, so it never flashes before the script loads.

Three tabs on the element’s own markup — arrow keys move between them.

About

A lightweight, accessible tab interface web component with keyboard navigation. Ships only structural CSS — you bring your own styles.

Features

  • Fully Accessible - Built following WAI-ARIA Tab pattern guidelines
  • Custom Events - Listen for tab changes with detailed event data
  • Keyboard Navigation - Complete keyboard support for accessibility
  • Controlled - Drive the active tab with the reflected active attribute
  • Dynamic - Tabs and panels can be added, removed, or reordered after mount
  • Auto Consistency - Fills in missing tab buttons or panels at first connect

Usage

<script type="module">
  import '@magic-spells/tab-group';
</script>

<tab-group>
  <tab-list>
    <tab-button>First Tab</tab-button>
    <tab-button>Second Tab</tab-button>
    <tab-button>Third Tab</tab-button>
  </tab-list>

  <tab-panel>
    <h3>First Tab Content</h3>
    <p>This is the content for the first tab.</p>
  </tab-panel>

  <tab-panel>
    <h3>Second Tab Content</h3>
    <p>This is the content for the second tab.</p>
  </tab-panel>

  <tab-panel>
    <h3>Third Tab Content</h3>
    <p>This is the content for the third tab.</p>
  </tab-panel>
</tab-group>

Attributes

AttributeElementDescriptionDefault
active0-based index of the active tab. Set it to switch tabs; the component reflects it back on every click and keypress, so it is always the source of truth. Out-of-range, non-numeric, or disabled indices are ignored. Programmatic activation (attribute, .active property, or an authored active at first connect) updates the roving tabindex but does not move focus — only a click or key press does.0
disabledMakes the tab unactivatable: clicks are ignored, arrow / Home / End roving skips it, and setting active to its index does nothing. The component writes aria-disabled="true" and tabindex="-1".none
animate-out-classCSS class for exit animation on outgoing panelnone
animate-in-classCSS class for enter animation on incoming panelnone
animate-timeoutFallback timeout (ms) if animationend doesn't fire500

About, features, usage and options are taken from the package README.