Skip to content

Tabs ​

The component only handles the rendering of the tab headers. The display of the tabbed content itself (depending on the activeIndex property) must be dealt with separately. Tabs are defined by an array of objects. Each of these objects

  • must provide a name property
  • and optionally a
    • disabled (Boolean)
    • icon (Component)
    • and badge (String) property

On small screens the tabs fall back to a select element.

Default Component ​

js
const tabs = ref({
    items: [
      { name: 'Profile', badge: '!', icon: UserIcon },
      { name: 'Tech' },
      { name: 'Intelligence', disabled: true },
      { name: 'Strategy' },
      { name: 'Confidential', disabled: true, badge: '10', icon: ShieldExclamationIcon }
    ],
    activeIndex: 0
})
html
<tabs :items="tabs.items" v-model:active-index="tabs.activeIndex" />

Result

Component Using Slots ​

html
<tabs :items="tabs.items" v-model:active-index="tabs.activeIndex">
    <template #icon="slotProps">
        <component v-if="slotProps.tab.icon" :is="slotProps.tab.icon" class="size-5 mr-2" fill="currentColor" />
    </template>
    <template #default="slotProps">
        <strong>{{ slotProps.tab.name }}</strong>
    </template>
    <template #badge="slotProps">
        <span class="ml-2 text-sm" v-if="slotProps.tab.badge">[{{ slotProps.tab.badge }}]</span>
    </template>
</tabs>

Result

Properties ​

NameTypeDefaultDescription
activeIndexNumber0determines which tab is selected
itemsObject[][]An array of objects determining the appearance and interactivity of each tab

Events ​

NameArgumentsDescription
update:activeIndexindex - NumberEmitted when tab is clicked (or selected)

Slots ​

NameScopedDescription
defaulttab - the data defining the currently rendered tabSlot which holds the name of the tab
icontab - the data defining the currently rendered tabSlot which contains the icon displayed to the left of the name
badgetab - the data defining the currently rendered tabSlot which contains the badge displayed to the right of the name