Skip to content

Tabs

TuiTabs is an extremely flexible tab switching component. It breaks the limitations of traditional Tabs that can only be displayed horizontally, supporting layouts in all four directions (up, down, left, right), and providing a variety of appearance styles. It can be used both as a content switcher and as an in-page navigation bar.

Core Features

  • Omnidirectional Layout: Supports the faceTo attribute to control tab orientation (up/down/left/right), easily implementing side navigation or bottom menus.
  • Three Appearances: Provides three styles: simple, card, and button (button/segmented controller).
  • Dual-Mode Rendering: Supports pure data-driven rendering via the options array, as well as slot-based development using the <TuiTab> component.
  • Smart Scrolling: Supports enabling scrollable mode for scrolling when the number of tabs exceeds the container size.
  • Badge Integration: Built-in Badge support to easily display unread counts or status markers.

Basic Usage

Component Slot Mode

Build tabs using the <TuiTab> sub-component. This is the most intuitive usage, suitable for scenarios requiring high customization of each tab's content.

html
<script setup>
import { ref } from 'vue';
const activeName = ref(0);
</script>

<template>
  <TuiTabs v-model="activeName">
    <TuiTab :value="0" label="User Management" icon="tui-icon ti-user" />
    <TuiTab :value="1" label="System Settings" icon="tui-icon ti-settings" />
    <TuiTab :value="2" label="Permission Config" disabled />
  </TuiTabs>
</template>

Data Driven Mode

Pass a configuration array through the options attribute. The code is more concise and suitable for dynamically generated tab lists.

html
<script setup>
import { ref } from 'vue';
const activeId = ref('a');

const tabOptions = [
  { label: 'Home', value: 'a', icon: 'ti-home' },
  { label: 'Messages', value: 'b', count: 12, tagType: 'danger' }, // With Badge
  { label: 'Settings', value: 'c' }
];
</script>

<template>
  <TuiTabs v-model="activeId" :options="tabOptions" />
</template>

Appearance Styles

Switch visual styles through the appearance attribute.

  • simple (Default): A minimalist style that indicates the selected state with an underline (or side line).
  • card: A card style that simulates folder tabs with a border wrap.
  • button: A button style (segmented controller), often used for mode switching within forms.
html
<template>
  <TuiTabs appearance="card" v-model="val1" :options="opts" />
  
  <TuiTabs 
    appearance="button" 
    :tagConfig="{ tone: 'strong', round: true }" 
    v-model="val2" 
    :options="opts" 
  />
</template>

Orientation and Text Layout

The power of TuiTabs lies in its ability to adapt to various layout requirements.

  • faceTo: Controls the position of the Tab bar relative to the content.
    • up (Default): Standard top navigation.
    • down: Bottom navigation.
    • left: Left vertical navigation.
    • right: Right vertical navigation.
  • textDirection: Controls the text arrangement direction.
    • h (Default): Horizontal arrangement.
    • v: Vertical arrangement (often used with faceTo="left/right" to achieve a vintage or special sidebar effect).
html
<template>
  <TuiTabs 
    faceTo="left" 
    textDirection="v" 
    style="height: 400px"
    v-model="active" 
    :options="sideOptions" 
  />
</template>

Scroll Mode

When the number of tabs exceeds the container width (or height), set scrollable to true to enable scroll mode. The component will automatically display left/right (or up/down) switching arrows.

html
<template>
  <div style="width: 400px">
    <TuiTabs 
      scrollable 
      :scrollOffset="50"
      v-model="active" 
      :options="longOptions" 
    />
  </div>
</template>

Badges and Status

Each Tab item supports displaying a Badge.

  • count: The numerical value or text to display.
  • tagType: The semantic color of the badge (primary, danger, warning, etc.).
  • tagConfig: Configuring tagConfig on TuiTabs allows unified control of all badge styles (such as round, tone).
html
<template>
  <TuiTabs 
    :tagConfig="{ tone: 'strong', round: true }" 
    :options="[
       { label: 'Todo', count: 5, tagType: 'danger' },
       { label: 'In Progress', count: 12, tagType: 'primary' }
    ]" 
  />
</template>

API Reference

TuiTabs Props

PropertyTypeDefaultDescription
modelValueString/Number-Two-way binding. Currently selected Tab value.
optionsArray[]Data source configuration. See TuiTab Props below for item object structure.
appearanceString'simple'Appearance style. Options: simple, card, button.
faceToString'up'Orientation. Options: up, down, left, right.
textDirectionStringnullText direction. Options: h (horizontal), v (vertical). Auto-adapts if empty.
sizeString'default'Size. Options: default, large, small.
alignStringnullAlignment. Options: start, center, end.
hideBaseLineBooleanfalseWhether to hide the bottom decorative line (only valid in simple/card modes).
itemMaxWidthNumber/String-Maximum width of a single Tab item.
scrollableBooleanfalseWhether to enable scroll mode.
scrollOffsetNumber0Extra offset when scrolling.
tagConfigObject-Props passed transparently to the internal TuiTag components (e.g., tone, round).
tipConfigObject-Unified configuration passed to Tooltip.

TuiTab Props (or Options Object Fields)

PropertyTypeDefaultDescription
valueString/NumberRequiredUnique identification value.
labelString-Tab text (default slot content in Slot mode).
iconStringnullIcon class name.
countNumber0Badge value. Displays when greater than 0.
tagTypeString'default'Badge color type (danger, primary, etc.).
disabledBooleanfalseWhether the option is disabled.

Events

Event NameDescriptionCallback Parameters
changeTriggered when switching options.`(value: String
update:modelValueTwo-way binding update.(value)

Released under the MIT License.