Vitral 0.2.18
Panel

Tabs

Views that share one place on the page, switched by a list of tabs.

Import

main.ts
import { Tabs } from '@vitral/vue';

Basic

Files you opened in the last week.

value: recent
<script setup lang="ts">import { Tab, TabList, TabPanel, TabPanels, Tabs } from '@vitral/vue';import { ref } from 'vue'; const tab = ref<string | number>('recent');const views = [    { value: 'recent', label: 'Recent', body: 'Files you opened in the last week.' },    { value: 'shared', label: 'Shared with me', body: 'Files other people gave you access to.' },    { value: 'favorites', label: 'Favorites', body: 'Files you starred.' },    { value: 'trash', label: 'Recycle bin', body: 'Deleted files, kept for 30 days.', disabled: true }];</script> <template>    <Tabs v-model:value="tab" style="width: 100%">        <TabList aria-label="Files">            <Tab v-for="v in views" :key="v.value" :value="v.value" :disabled="v.disabled">{{ v.label }}</Tab>        </TabList>        <TabPanels>            <TabPanel v-for="v in views" :key="v.value" :value="v.value">                <p style="margin: 0">{{ v.body }}</p>            </TabPanel>        </TabPanels>    </Tabs>    <small style="color: var(--vt-text-muted-color)">value: {{ tab }}</small></template>

Scrollable

`scrollable` lets tabs that do not fit scroll along the strip, across or upright. The buttons move nearly a page at a time; `scroll-buttons` puts one at each end (`sides`, the default, each shown only while there is more that way), both together at the `start` or the `end`, or `none`. The selected tab is always brought into view — press End on the tabs to see it follow.

The report for January.

The report for January.

<script setup lang="ts">import { SelectButton, Tab, TabList, TabPanel, TabPanels, Tabs } from '@vitral/vue';import { ref } from 'vue'; const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];const tab = ref('January');const upright = ref('January');const buttons = ref<'sides' | 'start' | 'end' | 'none'>('sides');</script> <template>    <div style="display: flex; flex-direction: column; gap: 1rem; width: 100%">        <SelectButton v-model="buttons" :options="['sides', 'start', 'end', 'none']" :allow-empty="false" aria-label="Where the buttons go" />        <Tabs v-model:value="tab" scrollable :scroll-buttons="buttons" style="width: 100%; max-width: 32rem">            <TabList aria-label="Months">                <Tab v-for="m in months" :key="m" :value="m">{{ m }}</Tab>            </TabList>            <TabPanels>                <TabPanel v-for="m in months" :key="m" :value="m">                    <p style="margin: 0">The report for {{ m }}.</p>                </TabPanel>            </TabPanels>        </Tabs>        <!-- Upright, the strip scrolls within the height the Tabs are given. -->        <Tabs v-model:value="upright" orientation="vertical" scrollable :scroll-buttons="buttons" style="width: 100%; height: 14rem">            <TabList aria-label="Months, upright">                <Tab v-for="m in months" :key="m" :value="m">{{ m }}</Tab>            </TabList>            <TabPanels>                <TabPanel v-for="m in months" :key="m" :value="m">                    <p style="margin: 0">The report for {{ m }}.</p>                </TabPanel>            </TabPanels>        </Tabs>    </div></template>

Vertical

Name, email and password.

<script setup lang="ts">import { Tab, TabList, TabPanel, TabPanels, Tabs } from '@vitral/vue';import { ref } from 'vue'; const vertical = ref<string | number>(0);</script> <template>    <Tabs v-model:value="vertical" orientation="vertical" style="width: 100%">        <TabList aria-label="Settings">            <Tab :value="0">Account</Tab>            <Tab :value="1">Notifications</Tab>            <Tab :value="2">Billing</Tab>        </TabList>        <TabPanels>            <TabPanel :value="0"><p style="margin: 0">Name, email and password.</p></TabPanel>            <TabPanel :value="1"><p style="margin: 0">What to be told about, and where.</p></TabPanel>            <TabPanel :value="2"><p style="margin: 0">Plan, invoices and payment method.</p></TabPanel>        </TabPanels>    </Tabs></template>

Styles

One component, five looks beside the default tinted selection: a quiet one with only the pill, an underline as wide as the tab, filled pills, a segmented control and tabs with an icon and a count. Each is the component's tokens changed for one instance with `dt` — the segmented track adds a style through `pt` — so a preset gives every Tabs the same look by setting the same tokens.

Quiet
Underline
Pills
Segmented
Icons and a count

Activity lives here.

<script setup lang="ts">import { Badge, Icon, Tab, TabList, TabPanel, TabPanels, Tabs } from '@vitral/vue';import { ref } from 'vue'; const views = [    { value: 'overview', label: 'Overview', icon: 'home' },    { value: 'activity', label: 'Activity', icon: 'bell', count: 4 },    { value: 'files', label: 'Files', icon: 'folder' },    { value: 'settings', label: 'Settings', icon: 'sliders' }];const quiet = ref('overview');const underline = ref('overview');const pills = ref('activity');const segmented = ref('files');const withIcons = ref('activity'); // Every look below is the same component with its tokens changed for this// instance (`dt`), and — for the segmented strip's track — a class or a style// through pass-through (`pt`). A preset sets the same tokens for every Tabs. /** Quieter than the default: no tint behind the selected tab, only the pill under it. */const quietTokens = { tabs: { tab: { activeBackground: 'transparent', activeColor: '{text.hoverColor}' } } }; /** An underline as wide as the tab, over a hairline along the whole strip. */const underlineTokens = {    tabs: {        tablist: { borderWidth: '1px', gap: '0' },        tab: { borderRadius: '0', hoverBackground: 'transparent', activeBackground: 'transparent', activeColor: '{text.hoverColor}', padding: '0.625rem 1rem' },        indicator: { width: '100%', thickness: '2px', borderRadius: '0' }    }}; /** Filled pills: the selected tab is the solid accent, and the indicator steps aside. */const pillTokens = {    tabs: {        tablist: { gap: '0.375rem' },        tab: { borderRadius: '{borderRadius.pill}', padding: '0.375rem 0.875rem', activeBackground: '{primary.color}', activeColor: '{primary.contrastColor}' },        indicator: { thickness: '0' }    }}; /** A segmented control: a track, and the selected tab raised on it. */const segmentedTokens = {    tabs: {        tablist: { padding: '0.25rem', gap: '0.25rem' },        tab: { borderRadius: '{borderRadius.md}', activeBackground: '{content.background}', activeColor: '{text.hoverColor}', hoverBackground: 'transparent' },        indicator: { thickness: '0' }    }};const trackPt = { tablist: { style: 'background: var(--vt-content-hover-background); border-radius: var(--vt-border-radius-lg); align-self: flex-start' } };const raisedPt = { tab: ({ state }: { state: unknown }) => ((state as { selected?: boolean }).selected ? { style: 'box-shadow: 0 1px 2px rgb(0 0 0 / 0.12)' } : {}) };</script> <template>    <div style="display: grid; gap: 1.75rem; width: 100%">        <section>            <small class="demo-caption">Quiet</small>            <Tabs v-model:value="quiet" :dt="quietTokens">                <TabList aria-label="Quiet">                    <Tab v-for="v in views" :key="v.value" :value="v.value">{{ v.label }}</Tab>                </TabList>            </Tabs>        </section>         <section>            <small class="demo-caption">Underline</small>            <Tabs v-model:value="underline" :dt="underlineTokens">                <TabList aria-label="Underline">                    <Tab v-for="v in views" :key="v.value" :value="v.value">{{ v.label }}</Tab>                </TabList>            </Tabs>        </section>         <section>            <small class="demo-caption">Pills</small>            <Tabs v-model:value="pills" :dt="pillTokens">                <TabList aria-label="Pills">                    <Tab v-for="v in views" :key="v.value" :value="v.value">{{ v.label }}</Tab>                </TabList>            </Tabs>        </section>         <section>            <small class="demo-caption">Segmented</small>            <Tabs v-model:value="segmented" :dt="segmentedTokens">                <TabList aria-label="Segmented" :pt="trackPt">                    <Tab v-for="v in views" :key="v.value" :value="v.value" :pt="raisedPt">{{ v.label }}</Tab>                </TabList>            </Tabs>        </section>         <section>            <small class="demo-caption">Icons and a count</small>            <Tabs v-model:value="withIcons" :dt="underlineTokens">                <TabList aria-label="With icons">                    <Tab v-for="v in views" :key="v.value" :value="v.value">                        <Icon :icon="v.icon" />                        {{ v.label }}                        <Badge v-if="v.count" :value="v.count" severity="danger" />                    </Tab>                </TabList>                <TabPanels>                    <TabPanel v-for="v in views" :key="v.value" :value="v.value">                        <p style="margin: 0">{{ v.label }} lives here.</p>                    </TabPanel>                </TabPanels>            </Tabs>        </section>    </div></template> <style scoped>.demo-caption {    display: block;    margin-bottom: 0.375rem;    color: var(--vt-text-muted-color);}</style>

Manual activation

With `select-on-focus` off, the arrows only move focus; Enter or Space selects.

Rendered only while selected (`lazy`).

<script setup lang="ts">import { Tab, TabList, TabPanel, TabPanels, Tabs } from '@vitral/vue';</script> <template>    <Tabs value="a" :select-on-focus="false" lazy>        <TabList aria-label="Manual">            <Tab value="a">Overview</Tab>            <Tab value="b">Activity</Tab>            <Tab value="c">Members</Tab>        </TabList>        <TabPanels>            <TabPanel value="a"><p style="margin: 0">Rendered only while selected (`lazy`).</p></TabPanel>            <TabPanel value="b"><p style="margin: 0">Recent activity.</p></TabPanel>            <TabPanel value="c"><p style="margin: 0">Who is in the project.</p></TabPanel>        </TabPanels>    </Tabs></template>

API

Read from packages/vue/src/components/Tabs/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
orientation 'horizontal' | 'vertical'Tabs above the panels (the default) or beside them.
lazy booleanRender a panel only while its tab is selected.
selectOnFocus booleanSelect a tab as soon as the arrow keys reach it: the APG's automatic activation, and the default. Off, the arrows only move focus and Enter/Space select.
scrollable booleanTabs that do not fit scroll along the strip, with a button at each end that has more to show; the selected tab is always brought into view.
scrollButtons 'sides' | 'start' | 'end' | 'none'Where a scrollable strip's buttons go: one at each end (`'sides'`, the default), both together at the start or at the end, or none — the arrow keys, the wheel and a swipe still scroll it.

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Slots

NameSlot propsDescription
default ——