Tabs
A versatile and accessible Tabs component for organizing content in panels.
Demo
<template>
<TabsContainer>
<TabBar
v-model="activeTabIndex"
:tabs
/>
<TabContent v-if="activeTabIndex === 0">
<ContentPlaceholder text="Content 1"/>
</TabContent>
<TabContent v-else-if="activeTabIndex === 1">
<ContentPlaceholder text="Content 2"/>
</TabContent>
<TabContent v-else-if="activeTabIndex === 2">
<ContentPlaceholder text="Content 3"/>
</TabContent>
</TabsContainer>
</template>
<script setup lang="ts">
// States
const activeTabIndex = ref(0)
// Data
const tabs: TabItem[] = [
{
text: 'Tab 1',
},
{
text: 'Tab 2',
},
{
text: 'Tab 3',
},
]
</script>
Components
| Name | Description |
|---|---|
TabBar | Displays the tabs items. |
TabContent | Displays the tab item content. |
TabContainer | Groups and styles the TabBar and the TabContent. |
TabBar
Props
| Props | Default | Type |
|---|---|---|
tabs | `An example array` | TabItem[] |
modelValue | 0 | number |
tabStyle | TabStyle.UNDERLINE | TabStyle |
tabSize | TabSize.LG | TabSize |
decoration | TabDecoration.NONE | TabDecoration |
hasContainer | false | boolean |
isContainerFullWidth | false | boolean |
disabled | false | boolean |
prefetchOn | PrefetchOn.VISIBILITY | PrefetchOnStrategy |
tabs
Sets the tab items.
<template>
<TabBar :tabs="exampleTabs" />
</template>
<script setup lang="ts">
const exampleTabs: TabItem[] = [
{
text: 'Tab 1',
},
{
text: 'Tab 2',
},
{
text: 'Tab 3',
},
]
</script>
TypeScript interface
interface TabItem {
text: string
icon?: string
imgUrl?: string
badgeValue?: number | string
to?: string
disabled?: boolean
}
modelValue
The value of the currently active tab.
<template>
<TabBar v-model="activeTabIndex" />
</template>
<script setup lang="ts">
const activeTabIndex = ref(0)
</script>
tabStyle
The style of the tabs. It uses the TabStyle enum.
<template>
<TabBar :tabStyle="TabStyle.PILL" />
</template>
Options
| Value | Description |
|---|---|
UNDERLINE | Underline-styled tab |
PILL | Primary brand pill-styled tab |
PILL_MONOCRHOME | Neutral color pill-styled tab |
tabSize
Sets the size of the tabs. It uses the TabSize enum.
<template>
<TabBar :tabSize="TabSize.SM" />
</template>
Options
| Value | Description |
|---|---|
LG | Large size tab |
MD | Medium size tab |
SM | Small size tab |
decoration
Sets the type of decoration of the tabs. It uses the TabDecoration enum.
<template>
<TabBar
:decoration="TabDecoration.IMAGE" />
:tabs="exampleTabs"
/>
</template>
<script setup lang="ts">
const exampleTabs: TabItem[] = [
{
text: 'Tab 1',
imgUrl : '....'
},
{
text: 'Tab 2',
imgUrl : '....'
},
{
text: 'Tab 3',
imgUrl : '....'
},
]
</script>
Options
| Value | Description |
|---|---|
NONE | Does not use decoration. |
IMAGE | Displays an image at the left side of the tab text. Requires to use the 'imgUrl' key inside the object array. |
ICON | Displays an icon at the left side of the tab text. Requires to use the 'icon' key inside the object array. |
hasContainer
Adds a border and padding to the TabBar component.
<TabBar
...
:hasContainer="true"
/>
</template>
isContainerFullWidth
When hasContainer is true, this prop makes the container take the full width of its parent.
<TabBar
...
:hasContainer="true"
:isContainerFullWidth="true"
/>
</template>
disabled
Disables the entire TabBar interaction state.
<template>
<TabBar
:tabs="exampleTabs"
:disabled="true"
/>
</template>
prefetchOn
Controls when tab route targets should be prefetched. It uses either the PrefetchOnStrategy type or the PrefetchOn enum.
<template>
<TabBar
:tabs="exampleTabs"
:prefetchOn="PrefetchOn.INTERACTION"
/>
</template>
Options
| Value | Description |
|---|---|
VISIBILITY | Prefetches routes based on visibility strategy. |
INTERACTION | Prefetches routes when users hover or focus a tab with a route target. |
You can also pass an object strategy:
{
visibility: true,
interaction: true,
}
TabContent
Wraps the content of the tab.
Use v-if directive to display the correct index content.
<template>
<TabsContainer>
<TabBar
...
/>
<TabContent v-if="activeTabIndex === 0">
<!-- Content 1 -->
</TabContent>
<TabContent v-else-if="activeTabIndex === 1">
<!-- Content 2 -->
</TabContent>
<!-- More tabs -->
</TabsContainer>
</template>
<script setup lang="ts">
// States
const activeTabIndex = ref(0)
</script>
TabsContainer
Wraps the TabBar and TabContent components.
<template>
<TabsContainer>
<TabBar
...
/>
<TabContent v-if="activeTabIndex === 0">
<!-- Content 1 -->
</TabContent>
...
</TabsContainer>
</template>