Skip to content

Tabs

Divide data collections that are related but belong to different categories. YH-UI's Tabs combine the best features of Element Plus, Naive UI, and Ant Design, while introducing a unique Segment styler and custom transition hooks.

Basic Usage

Basic and concise tabs. Use v-model to bind the currently active tab name.

User Management
Basic Usage

Custom Trigger

Specify the tab switching trigger via the trigger property. Options: click (default), hover.

Hover over a tab to switch
Custom Trigger

Card Style

Set type="card" to change the look of the tabs to cards.

User Management
Card Style

Bordered Card

Set type="border-card" for a bordered card presentation.

User Management
Bordered Card

Segment Style

Set type="segment" for an iOS-style segment control effect, ideal for view switching.

Day View Content
Segment Style

Tab Position

Set the position of the tabs via tab-position. Options: top, right, bottom, left.

User Management Content
Tab Position

Custom Indicator Style

The default indicator is short (40px) and centered. Control its size via indicator-width and indicator-height. Set them to auto to make the indicator span the full tab width. Color can be customized via active-color and inactive-color.

User Management Content
Custom Indicator Style

Stretched Tabs

Set stretch to make the tabs fill the container width.

User Management Content
Stretched Tabs

Dynamic Tabs

Set editable (equivalent to closable + addable) to allow dynamic addition and removal of tabs.

Tab 1 Content
Dynamic Tabs

Custom Adder Trigger

Trigger tab addition via an external button instead of the built-in + button. Set :addable="false" to hide the built-in button and implement your own logic.

Tab 1 Content
Custom Adder Trigger

Before Change Hook

Control tab switching with the before-leave hook. Return false or a Promise.reject to prevent switching.

User Management
Before Change Hook

Lazy Render

Set lazy to delay rendering of tab content until the tab is first activated.

Content loaded instantly
Lazy Render

Usage in Nuxt

The component is fully adapted for Nuxt 3, supporting auto-import and SSR.

Content 1
Nuxt Adaptation

API

Tabs Props

NameDescriptionTypeDefault
model-value / v-modelBinding value, currently active tab namestring | number''
typeTab style type'line' | 'card' | 'border-card' | 'segment''line'
tab-positionPosition of tabs'top' | 'right' | 'bottom' | 'left''top'
closableWhether tabs are closablebooleanfalse
addableWhether tabs can be addedbooleanfalse
editableWhether tabs are editable (equivalent to closable + addable)booleanfalse
draggableWhether tabs are draggable for reorderingbooleanfalse
before-leaveHook before switch; return false to stop toggle(newName, oldName) => boolean | Promise<boolean>
stretchWhether tabs should span the full widthbooleanfalse
nav-classCustom class name for the navigation barstring''
content-classCustom class name for the content areastring''
indicator-widthIndicator width (auto spans the full tab)string'' (CSS default 40px)
indicator-heightIndicator height (auto spans the full tab)string'' (CSS default 20px)
active-colorColor for the active state (text and indicator)string''
inactive-colorColor for the inactive statestring''
triggerSwitch trigger'click' | 'hover''click'

Tabs Events

NameDescriptionParameters
tab-clickTriggered when a tab is clicked(pane: TabPaneConfig, ev: Event) => void
tab-changeTriggered when the active tab changes(name: string | number) => void
tab-removeTriggered when the close button is clicked(name: string | number) => void
tab-addTriggered when the add button is clicked() => void
tab-drag-endTriggered when drag-and-drop ends(names: (string | number)[]) => void

Tabs Slots

NameDescriptionParameters
defaultContent of TabPane
labelCustom tab label{ pane: TabPaneConfig }
add-iconCustom icon for the add button

Tabs Expose

You can access the Tabs instance via ref and call these methods:

NameDescriptionType
addTabTriggers the tab add event (use with @tab-add)() => void
setActiveTabActivates a specific tab(name: string | number) => void
activeTabCurrently active tab name (reactive)Ref<string | number>

TabPane Props

NameDescriptionTypeDefault
nameUnique identifier (Required)string | number
labelTab label/titlestring''
disabledWhether the tab is disabledbooleanfalse
closableWhether the tab is closable (overrides Tabs prop)booleanundefined
lazyWhether to lazy-render the contentbooleanfalse
iconIcon class namestring''

TabPane Slots

NameDescriptionParameters
defaultContent of the tab

Theme Variables

VariableDescriptionDefault
--yh-tabs-header-heightNavigation bar height40px
--yh-tabs-active-colorActive state colorvar(--yh-color-primary)
--yh-tabs-text-colorText colorvar(--yh-text-color-primary)
--yh-tabs-disabled-colorDisabled state colorvar(--yh-text-color-disabled)
--yh-tabs-border-colorBorder colorvar(--yh-border-color-light)
--yh-tabs-indicator-widthIndicator width (horizontal layout)40px
--yh-tabs-indicator-heightIndicator height (vertical layout)20px

Released under the MIT License.