Tab Group
Tab list and tab panel elements with roving focus and three ready-made skins.
v1.2.0@magic-spells/tab-group
Live demo
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
| Attribute | Element | Description | Default |
|---|---|---|---|
| active | 0-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 | |
| disabled | Makes 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-class | CSS class for exit animation on outgoing panel | none | |
| animate-in-class | CSS class for enter animation on incoming panel | none | |
| animate-timeout | Fallback timeout (ms) if animationend doesn't fire | 500 |
About, features, usage and options are taken from the package README.