Zubra UI
Code for
GitHub

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

Compiled (any project)
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
One file, no dependencies (5.8 KB gzipped)
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
.zb source (to edit it with Zubra)
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
No build: a script tag, straight from this site
HTML
<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

index.html
<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>
Example.jsx
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>
  );
}
Example.vue
<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('-') } } }) -->
Example.svelte
<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>
example.component.ts
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

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
valuestring""
tabs
property only
{ value, label }[][]
labelstring""
manualbooleanfalse
Events
EventWhen
valuechangeAnother tab was chosen; detail is its value.
Slots
SlotFor
(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.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour