Skip to content

Tabs

The Tabs component provides tabbed navigation with an optional panel area. Use it with v-model for keyboard and mouse navigation and flexible tab definitions.

Basic Usage

vue
<template>
  <Col :gap="1">
    <TextBox bold color="cyan">Tabs</TextBox>

    <Tabs v-model="activeTab" :tabs="tabs">
      <template #default="{ activeTab }">
        <TextBox v-if="activeTab === 'general'">
          General settings panel content.
        </TextBox>
        <TextBox v-else-if="activeTab === 'advanced'" color="yellow">
          Advanced settings panel content.
        </TextBox>
        <TextBox v-else color="green">
          About panel content.
        </TextBox>
      </template>
    </Tabs>
  </Col>
</template>

<script setup>
import { ref } from 'vue';
import { Col, Tabs, TextBox } from 'vuetty';

const tabs = [
  { value: 'general', label: 'General' },
  { value: 'advanced', label: 'Advanced' },
  { value: 'about', label: 'About' },
  { value: 'disabled', label: 'Disabled', disabled: true }
];

const activeTab = ref('general');
</script>

Tabbed navigation with panel content

Props

NameTypeDefaultDescription
modelValuestring \| numbernullActive tab value (v-model). Defaults to first enabled tab when null
tabsarray[]List of tabs (required)
widthnumberundefinedPanel width in characters
disabledbooleanfalseDisable navigation and selection
colorstring-Base text color (chalk color names)
bgstring-Background color
focusColorstring'cyan'Border color when focused
activeColorstring'green'Color for the active tab label and underline
highlightColorstring'yellow'Color for the highlighted tab (keyboard focus)
panelBorderbooleantrueShow a panel border under the tab bar
panelBorderStylestring'rounded'Panel border style (same styles as Box)
panelPaddingnumber1Panel padding (characters)
hintstring \| boolean'default'Hint text when focused (false to hide)

Layout Props (Box Props)

NameTypeDefaultDescription
flexnumber \| stringnullFlex shorthand when inside a flex container
flexGrownumbernullFlex grow factor
flexShrinknumbernullFlex shrink factor
flexBasisnumber \| stringnullFlex basis
alignSelfstringnullSelf alignment: 'auto', 'flex-start', 'flex-end', 'center', 'stretch', 'baseline'
widthnumber \| stringnullWidth (chars or %)
heightnumber \| stringnullHeight (rows)
minWidthnumbernullMinimum width
maxWidthnumbernullMaximum width
minHeightnumbernullMinimum height
maxHeightnumbernullMaximum height
paddingnumbernullPadding
paddingLeftnumbernullLeft padding
paddingRightnumbernullRight padding
paddingTopnumbernullTop padding
paddingBottomnumbernullBottom padding
marginnumbernullMargin
marginLeftnumbernullLeft margin
marginRightnumbernullRight margin
marginTopnumbernullTop margin
marginBottomnumbernullBottom margin

Tabs Format

Tabs can be objects or primitive values:

js
// Object format (recommended)
{
  value: 'general',  // value used by v-model
  label: 'General',  // display label
  disabled: false    // optional
}

// Primitive format (label derived from value)
'Profile'
42

Panel Content (Default Slot)

The default slot receives { activeTab }, letting you render content based on the active tab.

vue
<Tabs v-model="activeTab" :tabs="tabs">
  <template #default="{ activeTab }">
    <TextBox>Active: {{ activeTab }}</TextBox>
  </template>
</Tabs>

Keyboard & Mouse

  • Arrow keys: move between tabs
  • Home/End: jump to first/last tab
  • Enter/Space: select highlighted tab
  • Type a letter: jump to the next tab starting with that letter
  • Mouse click: select a tab

Events

EventPayloadDescription
update:modelValuevalueEmitted when a tab is selected
changevalueEmitted when the selected tab changes
focus-Emitted when the component gains focus
blur-Emitted when the component loses focus

Examples

No Panel Border

vue
<template>
  <Tabs v-model="activeTab" :tabs="tabs" :panelBorder="false" :panelPadding="0">
    <template #default="{ activeTab }">
      <TextBox>Content for: {{ activeTab }}</TextBox>
    </template>
  </Tabs>
</template>

<script setup>
import { ref } from 'vue';
import { Tabs, TextBox } from 'vuetty';

const tabs = ['Home', 'Profile', 'Settings'];
const activeTab = ref('Home');
</script>

Custom Colors

vue
<template>
  <Tabs
    v-model="activeTab"
    :tabs="tabs"
    activeColor="magenta"
    highlightColor="cyan"
    focusColor="yellow"
  />
</template>

<script setup>
import { ref } from 'vue';
import { Tabs } from 'vuetty';

const tabs = ['Overview', 'Metrics', 'Logs'];
const activeTab = ref('Overview');
</script>

Usage with Other Components

Tabs pair well with layout and content components:

vue
<template>
  <Col :gap="1">
    <TextBox bold>Settings</TextBox>
    <Tabs v-model="activeTab" :tabs="tabs">
      <template #default="{ activeTab }">
        <Box :padding="1">
          <TextBox>Section: {{ activeTab }}</TextBox>
        </Box>
      </template>
    </Tabs>
  </Col>
</template>

<script setup>
import { ref } from 'vue';
import { Box, Col, Tabs, TextBox } from 'vuetty';

const tabs = ['General', 'Advanced', 'About'];
const activeTab = ref('General');
</script>

Released under the MIT License.