Tabs
Switch between related views without leaving the page. Same markup and props in every style: switch the style in the header to see it change.
Segmented
The default look. Arrow keys move between tabs. In HTML, add data-vin-tabs and include vinui.js once.
<div class="vin-tabs" data-vin-tabs style="width: 100%; max-width: 380px">
<div class="vin-tabs__list" role="tablist" aria-label="Account settings">
<button type="button" class="vin-tabs__tab" role="tab" id="ta-account" aria-selected="true" aria-controls="ta-account-panel">Account</button>
<button type="button" class="vin-tabs__tab" role="tab" id="ta-password" aria-selected="false" aria-controls="ta-password-panel" tabindex="-1">Password</button>
<button type="button" class="vin-tabs__tab" role="tab" id="ta-team" aria-selected="false" aria-controls="ta-team-panel" tabindex="-1">Team</button>
</div>
<div class="vin-tabs__panel" role="tabpanel" id="ta-account-panel" aria-labelledby="ta-account" tabindex="0">Change your name, email and profile picture.</div>
<div class="vin-tabs__panel" role="tabpanel" id="ta-password-panel" aria-labelledby="ta-password" tabindex="0" hidden>Update your password and turn on two-step sign-in.</div>
<div class="vin-tabs__panel" role="tabpanel" id="ta-team-panel" aria-labelledby="ta-team" tabindex="0" hidden>Invite people and manage their roles.</div>
</div>import { Tabs, TabList, Tab, TabPanel } from "@/components/vin/tabs";
export function TabsSegmented() {
return (
<Tabs defaultValue="account" style={{ width: "100%", maxWidth: 380 }}>
<TabList aria-label="Account settings">
<Tab value="account">Account</Tab>
<Tab value="password">Password</Tab>
<Tab value="team">Team</Tab>
</TabList>
<TabPanel value="account">Change your name, email and profile picture.</TabPanel>
<TabPanel value="password">Update your password and turn on two-step sign-in.</TabPanel>
<TabPanel value="team">Invite people and manage their roles.</TabPanel>
</Tabs>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Tabs, { TabList, Tab, TabPanel } from "@/components/vin/tabs.vue";
</script>
<template>
<Tabs default-value="account" style="width: 100%; max-width: 380px">
<TabList aria-label="Account settings">
<Tab value="account">Account</Tab>
<Tab value="password">Password</Tab>
<Tab value="team">Team</Tab>
</TabList>
<TabPanel value="account">Change your name, email and profile picture.</TabPanel>
<TabPanel value="password">Update your password and turn on two-step sign-in.</TabPanel>
<TabPanel value="team">Invite people and manage their roles.</TabPanel>
</Tabs>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Tabs from "$lib/components/vin/tabs.svelte";
import TabList from "$lib/components/vin/tabs-list.svelte";
import Tab from "$lib/components/vin/tabs-tab.svelte";
import TabPanel from "$lib/components/vin/tabs-panel.svelte";
</script>
<Tabs value="account" style="width: 100%; max-width: 380px">
<TabList aria-label="Account settings">
<Tab value="account">Account</Tab>
<Tab value="password">Password</Tab>
<Tab value="team">Team</Tab>
</TabList>
<TabPanel value="account">Change your name, email and profile picture.</TabPanel>
<TabPanel value="password">Update your password and turn on two-step sign-in.</TabPanel>
<TabPanel value="team">Invite people and manage their roles.</TabPanel>
</Tabs>Line
Underlined tabs for page sections and settings screens.
<div class="vin-tabs vin-tabs--line" data-vin-tabs style="width: 100%; max-width: 420px">
<div class="vin-tabs__list" role="tablist" aria-label="Project">
<button type="button" class="vin-tabs__tab" role="tab" id="tb-overview" aria-selected="true" aria-controls="tb-overview-panel">Overview</button>
<button type="button" class="vin-tabs__tab" role="tab" id="tb-activity" aria-selected="false" aria-controls="tb-activity-panel" tabindex="-1">Activity</button>
<button type="button" class="vin-tabs__tab" role="tab" id="tb-files" aria-selected="false" aria-controls="tb-files-panel" tabindex="-1">Files</button>
<button type="button" class="vin-tabs__tab" role="tab" id="tb-archive" aria-selected="false" aria-controls="tb-archive-panel" tabindex="-1" disabled>Archive</button>
</div>
<div class="vin-tabs__panel" role="tabpanel" id="tb-overview-panel" aria-labelledby="tb-overview" tabindex="0">12 open tasks, 3 due this week.</div>
<div class="vin-tabs__panel" role="tabpanel" id="tb-activity-panel" aria-labelledby="tb-activity" tabindex="0" hidden>Latest changes from your team.</div>
<div class="vin-tabs__panel" role="tabpanel" id="tb-files-panel" aria-labelledby="tb-files" tabindex="0" hidden>Shared documents and images.</div>
<div class="vin-tabs__panel" role="tabpanel" id="tb-archive-panel" aria-labelledby="tb-archive" tabindex="0" hidden>Archived items.</div>
</div>import { Tabs, TabList, Tab, TabPanel } from "@/components/vin/tabs";
export function TabsLine() {
return (
<Tabs defaultValue="overview" variant="line" style={{ width: "100%", maxWidth: 420 }}>
<TabList aria-label="Project">
<Tab value="overview">Overview</Tab>
<Tab value="activity">Activity</Tab>
<Tab value="files">Files</Tab>
<Tab value="archive" disabled>Archive</Tab>
</TabList>
<TabPanel value="overview">12 open tasks, 3 due this week.</TabPanel>
<TabPanel value="activity">Latest changes from your team.</TabPanel>
<TabPanel value="files">Shared documents and images.</TabPanel>
<TabPanel value="archive">Archived items.</TabPanel>
</Tabs>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Tabs, { TabList, Tab, TabPanel } from "@/components/vin/tabs.vue";
</script>
<template>
<Tabs default-value="overview" variant="line" style="width: 100%; max-width: 420px">
<TabList aria-label="Project">
<Tab value="overview">Overview</Tab>
<Tab value="activity">Activity</Tab>
<Tab value="files">Files</Tab>
<Tab value="archive" disabled>Archive</Tab>
</TabList>
<TabPanel value="overview">12 open tasks, 3 due this week.</TabPanel>
<TabPanel value="activity">Latest changes from your team.</TabPanel>
<TabPanel value="files">Shared documents and images.</TabPanel>
<TabPanel value="archive">Archived items.</TabPanel>
</Tabs>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Tabs from "$lib/components/vin/tabs.svelte";
import TabList from "$lib/components/vin/tabs-list.svelte";
import Tab from "$lib/components/vin/tabs-tab.svelte";
import TabPanel from "$lib/components/vin/tabs-panel.svelte";
</script>
<Tabs value="overview" variant="line" style="width: 100%; max-width: 420px">
<TabList aria-label="Project">
<Tab value="overview">Overview</Tab>
<Tab value="activity">Activity</Tab>
<Tab value="files">Files</Tab>
<Tab value="archive" disabled>Archive</Tab>
</TabList>
<TabPanel value="overview">12 open tasks, 3 due this week.</TabPanel>
<TabPanel value="activity">Latest changes from your team.</TabPanel>
<TabPanel value="files">Shared documents and images.</TabPanel>
<TabPanel value="archive">Archived items.</TabPanel>
</Tabs>Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add tabsimport { Tabs, TabList, Tab, TabPanel } from "@/components/vin/tabs";import Tabs, { TabList, Tab, TabPanel } from "@/components/vin/tabs.vue";import Tabs from "$lib/components/vin/tabs.svelte";
import TabList from "$lib/components/vin/tabs-list.svelte";
import TabPanel from "$lib/components/vin/tabs-panel.svelte";
import Tab from "$lib/components/vin/tabs-tab.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.
API
From spec/tabs.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
variant | segmentedline | segmented | vin-tabs--line |
value / defaultValueThe open tab (controlled or not). Use onValueChange to hear about changes. | string | — | aria-selected="true" on the tab |
TabList aria-labelNames the group of tabs for screen readers. | string | — | aria-label on [role=tablist] |
Tab / TabPanel valueLinks each tab to its panel. | string | — | aria-controls / aria-labelledby |
disabled (Tab) | boolean | false | disabled attribute |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<Tabs><TabList><Tab><TabPanel> | .vin-tabs.vin-tabs--line.vin-tabs__list.vin-tabs__tab.vin-tabs__panel |
Accessibility
- Follows the WAI-ARIA tabs pattern: role="tablist", "tab" and "tabpanel", linked with aria-controls and aria-labelledby.
- Only the open tab is in the Tab order; ← → move between tabs and Home/End jump to the first or last. Right-to-left layouts flip the arrows.
- Panels can take focus, so keyboard users reach their content straight after the tabs.
- The open tab is shown by more than colour: a raised surface or an underline.
Customize
Saved in this browser. Style and accent are in the header.