tab-list
Tabs: a tab list and the panels it switches between. The panels are the slotted elements with a data-tab attribute matching a tab's value; they get role=tabpanel, are labelled by their tab, and are hidden unless chosen. Arrow keys, Home and End move between the tabs (one tab stop), and the focused tab is chosen as it moves, unless manual, where Enter or Space chooses it. tabs is [{ value, label }]; value is two-way and defaults to the first tab.
Your name and photo, shown on your posts.
Next invoice on 1 December: $12.00.
Five seats, three used.
Try it: events appear here (valuechange).
Source: tab-list.zb, and its registry item.
Install
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/tab-list.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/tab-list.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/tab-list.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/tab-list.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/tab-list.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/tab-list.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/tab-list.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/tab-list.json
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/tab-list.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/tab-list.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/tab-list.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/tab-list.json
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/tab-list.js"></script>The compiled install writes src/components/zubra/tab-list.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.
Usage
<tab-list label="Account">
<p data-tab="profile">Your name and photo, shown on your posts.</p>
<p data-tab="billing">Next invoice on 1 December: $12.00.</p>
<p data-tab="team">Five seats, three used.</p>
</tab-list>
<script type="module">
import './components/zubra/tab-list.js';
const element = document.querySelector('tab-list');
element.value = 'profile';
element.tabs = [
{ value: 'profile', label: 'Profile' },
{ value: 'billing', label: 'Billing' },
{ value: 'team', label: 'Team' },
];
element.addEventListener('valuechange', (event) => console.log('valuechange', event.detail));
</script>import './components/zubra/tab-list.js';
const value = 'profile';
const tabs = [
{ value: 'profile', label: 'Profile' },
{ value: 'billing', label: 'Billing' },
{ value: 'team', label: 'Team' },
];
export function TabListExample() {
return (
<tab-list
label="Account"
value={value}
tabs={tabs}
onvaluechange={(event) => console.log('valuechange', event.detail)}
>
<p data-tab="profile">Your name and photo, shown on your posts.</p>
<p data-tab="billing">Next invoice on 1 December: $12.00.</p>
<p data-tab="team">Five seats, three used.</p>
</tab-list>
);
}<script setup>
import './components/zubra/tab-list.js';
const value = 'profile';
const tabs = [
{ value: 'profile', label: 'Profile' },
{ value: 'billing', label: 'Billing' },
{ value: 'team', label: 'Team' },
];
const onValuechange = (event) => console.log('valuechange', event.detail);
</script>
<template>
<tab-list
label="Account"
:value.prop="value"
:tabs.prop="tabs"
@valuechange="onValuechange"
>
<p data-tab="profile">Your name and photo, shown on your posts.</p>
<p data-tab="billing">Next invoice on 1 December: $12.00.</p>
<p data-tab="team">Five seats, three used.</p>
</tab-list>
</template>
<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) --><script>
import './components/zubra/tab-list.js';
const value = 'profile';
const tabs = [
{ value: 'profile', label: 'Profile' },
{ value: 'billing', label: 'Billing' },
{ value: 'team', label: 'Team' },
];
</script>
<tab-list
label="Account"
{value}
{tabs}
onvaluechange={(event) => console.log('valuechange', event.detail)}
>
<p data-tab="profile">Your name and photo, shown on your posts.</p>
<p data-tab="billing">Next invoice on 1 December: $12.00.</p>
<p data-tab="team">Five seats, three used.</p>
</tab-list>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/tab-list.js';
@Component({
selector: 'app-tab-list-example',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<tab-list
label="Account"
[value]="value"
[tabs]="tabs"
(valuechange)="onValuechange($event)"
>
<p data-tab="profile">Your name and photo, shown on your posts.</p>
<p data-tab="billing">Next invoice on 1 December: $12.00.</p>
<p data-tab="team">Five seats, three used.</p>
</tab-list>
`,
})
export class TabListExample {
value = 'profile';
tabs = [
{ value: 'profile', label: 'Profile' },
{ value: 'billing', label: 'Billing' },
{ value: 'team', label: 'Team' },
];
onValuechange(event: Event) {
console.log('valuechange', (event as CustomEvent).detail);
}
}API
| Property | Type | Default |
|---|---|---|
value | string | "" |
tabsproperty only | { value, label }[] | [] |
label | string | "" |
manual | boolean | false |
| Event | When |
|---|---|
valuechange | Another tab was chosen; detail is its value. |
| Slot | For |
|---|---|
(default) | The panels. |
Size
1.7 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 18.8 KB.