VTabs selects a tab and optionally displays its panel. It also supports a tab bar without panels.
Usage
vue
What the project is for.
What has happened lately.
<script setup lang="ts">
import { ref } from 'vue'
import { VTab, VTabPanel, VTabs } from 'vectis-ui'
const tab = ref('overview')
</script>
<template>
<VTabs v-model="tab" label="Project">
<VTab value="overview" label="Overview" />
<VTab value="activity" label="Activity" />
<template #panels>
<VTabPanel value="overview">What the project is for.</VTabPanel>
<VTabPanel value="activity">What has happened lately.</VTabPanel>
</template>
</VTabs>
</template>
Examples
Variants and tones
flat underlines the selected tab. outline, elevated and filled add a frame with a border, a shadow or a muted surface, and inset uses a recessed track. tone colours the selection.
Provide one matching panel per tab in panels, or omit this slot from the start. Hidden panels retain their state and form values. lazy delays mounting until the first opening.
vue
What the project is for.
Type here, switch tab and come back: the value is still there.
<script setup lang="ts">
import { ref } from 'vue'
import { VInput, VTab, VTabPanel, VTabs } from 'vectis-ui'
const withPanels = ref('overview')
const bare = ref('day')
</script>
<template>
<div class="demo">
<VTabs v-model="withPanels" label="Project">
<VTab value="overview" label="Overview" />
<VTab value="details" label="Details" />
<VTab value="history" label="History" />
<template #panels>
<VTabPanel value="overview">What the project is for.</VTabPanel>
<VTabPanel value="details">
<VInput label="Reference" model-value="INV-2481" />
<p class="note">Type here, switch tab and come back: the value is still there.</p>
</VTabPanel>
<VTabPanel value="history" lazy>Built the first time this tab is opened.</VTabPanel>
</template>
</VTabs>
<VTabs v-model="bare" variant="inset" label="Range">
<VTab value="day" label="Day" />
<VTab value="week" label="Week" />
<VTab value="month" label="Month" />
</VTabs>
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-6);
}
.note {
margin: var(--vectis-space-3) 0 0;
color: var(--vectis-color-text-muted);
font-size: var(--vectis-text-caption-size);
}
</style>
Alignment
align positions tabs when they do not fill the bar.
Manual activation moves focus with arrows and selects with Enter or Space. Automatic activation selects on focus; use it when panels appear immediately.
vue
manual, the default
What the project is for.
What has happened lately.
How it is configured.
automatic
What the project is for.
What has happened lately.
How it is configured.
<script setup lang="ts">
import { ref } from 'vue'
import { VTab, VTabPanel, VTabs } from 'vectis-ui'
const manual = ref('overview')
const automatic = ref('overview')
</script>
<template>
<div class="demo">
<div class="row">
<p class="caption">manual, the default</p>
<VTabs v-model="manual" label="Project, manual">
<VTab value="overview" label="Overview" />
<VTab value="activity" label="Activity" />
<VTab value="settings" label="Settings" />
<template #panels>
<VTabPanel value="overview">What the project is for.</VTabPanel>
<VTabPanel value="activity">What has happened lately.</VTabPanel>
<VTabPanel value="settings">How it is configured.</VTabPanel>
</template>
</VTabs>
</div>
<!-- Focus a tab and press an arrow key. -->
<div class="row">
<p class="caption">automatic</p>
<VTabs v-model="automatic" activation="automatic" label="Project, automatic">
<VTab value="overview" label="Overview" />
<VTab value="activity" label="Activity" />
<VTab value="settings" label="Settings" />
<template #panels>
<VTabPanel value="overview">What the project is for.</VTabPanel>
<VTabPanel value="activity">What has happened lately.</VTabPanel>
<VTabPanel value="settings">How it is configured.</VTabPanel>
</template>
</VTabs>
</div>
</div>
</template>
<style scoped>
.demo {
display: grid;
gap: var(--vectis-space-6);
}
.row {
display: grid;
gap: var(--vectis-space-2);
}
.caption {
margin: 0;
color: var(--vectis-color-text-muted);
font-size: var(--vectis-text-caption-size);
}
</style>
Disabled tabs
Disabled tabs are skipped. Keep the model on an enabled tab. Disabling the group leaves the current panel visible.
vue
What the project is for.
Never reached.
How it is configured.
<script setup lang="ts">
import { ref } from 'vue'
import { VTab, VTabPanel, VTabs } from 'vectis-ui'
const tab = ref('overview')
</script>
<template>
<VTabs v-model="tab" label="Project">
<VTab value="overview" label="Overview" />
<VTab value="activity" label="Activity" disabled />
<VTab value="settings" label="Settings" />
<template #panels>
<VTabPanel value="overview">What the project is for.</VTabPanel>
<VTabPanel value="activity">Never reached.</VTabPanel>
<VTabPanel value="settings">How it is configured.</VTabPanel>
</template>
</VTabs>
</template>