Skip to content

Tabs

YhTabs and YhTabPane divide related content into multiple panes. They support line, card, border-card, and segment styles, custom triggers, dynamic add/remove actions, lazy rendering, and theme overrides.

Divide related content into separate panes and switch between them by tab.

Basic Usage

Use v-model to bind the active tab name.

User Management
Basic Usage

Trigger Mode

Use trigger="hover" to activate tabs on hover instead of click.

Switch on hover
Trigger Mode

Card Styles

type="card" and type="border-card" provide alternate visual styles for tab navigation.

User Management
Card Style
User Management
Bordered Card

Segment Style

type="segment" renders tabs like a segmented control.

Day View
Segment Style

Tab Position

Use tab-position to move the navigation to the top, right, bottom, or left side.

User Management Content
Tab Position

Indicator and Stretch

Use active-color, inactive-color, indicator-width, and indicator-height to customize the line indicator. Use stretch to make tabs fill the available width.

User Management Content
Custom Indicator
User Management Content
Stretch

Editable Tabs

Use editable, or combine closable and addable, to build dynamic tab sets.

Tab 1 Content
Editable Tabs
Tab 1 Content
Custom Add Trigger

Before Leave Hook

before-leave can block tab switching by returning false or rejecting.

User Management
Before Leave Hook

Lazy Render

Set lazy on a tab pane to delay rendering its content until first activation.

Content loaded instantly
Lazy Render

Use in Nuxt

After installing @yh-ui/nuxt, YhTabs and YhTabPane can be used directly in Nuxt 3/4 pages and components.

Content 1
Use in Nuxt

API

Tabs Props

PropDescriptionTypeDefault
model-value / v-modelActive tab namestring | number''
typeTabs style'line' | 'card' | 'border-card' | 'segment''line'
tab-positionNavigation position'top' | 'right' | 'bottom' | 'left''top'
draggableDeclared prop for drag sorting. The current implementation does not consume it yet.booleanfalse
closableShow close buttonsbooleanfalse
addableShow built-in add buttonbooleanfalse
editableEquivalent to enabling both add and close actionsbooleanfalse
before-leaveHook called before switching tabs(newName: string | number, oldName: string | number) => boolean | Promise<boolean>undefined
stretchStretch tabs to fill available widthbooleanfalse
nav-classExtra class for the tab navigation wrapperstring''
content-classExtra class for the content wrapperstring''
indicator-widthCustom indicator widthstring''
indicator-heightCustom indicator heightstring''
active-colorActive text and indicator color overridestring''
inactive-colorInactive tab text color overridestring''
triggerActivation trigger'click' | 'hover''click'
theme-overridesComponent theme override variablesComponentThemeVarsundefined

Tabs Events

EventDescriptionParameters
update:modelValueTriggered when the active tab changes(name: string | number) => void
tab-clickTriggered when a tab header is clicked(pane: YhTabPaneConfig, ev: Event) => void
tab-changeTriggered after the active tab changes(name: string | number) => void
tab-removeTriggered when a tab close action is requested(name: string | number) => void
tab-addTriggered when an add action is requested() => void
tab-drag-endDeclared event for drag sorting. The current implementation does not emit it yet.(names: (string | number)[]) => void

Tabs Slots

SlotDescriptionParameters
defaultTab panes rendered inside YhTabs-
labelCustom tab label content. pane.name is normalized to string when registered.{ pane: YhTabPaneConfig }
add-iconCustom icon for the add button-

Tabs Expose

NameDescriptionType
addTabTrigger the add-tab flow() => void
setActiveTabActivate a tab by name(name: string | number) => void
activeTabCurrent active tab ref.Ref<string | number>

TabPane Props

PropDescriptionTypeDefault
nameUnique pane namestring | numberRequired
labelTab label textstring''
disabledDisable the tab panebooleanfalse
closableOverride whether this pane is closablebooleanundefined
lazyRender content only after first activationbooleanfalse
iconIcon class name shown before the labelstring''
theme-overridesComponent theme override variablesComponentThemeVarsundefined

TabPane Events

This component does not expose component events.

TabPane Slots

SlotDescriptionParameters
defaultPane content-

TabPane Expose

This component does not expose public instance methods or properties.

Type Exports

TypeDescription
YhTabsPropsTabs props type
YhTabsEmitsTabs emits type
YhTabsSlotsTabs slots type
YhTabsExposeTabs expose type
YhTabsTypeTabs style union
YhTabsPositionTabs position union
YhTabPaneConfigRegistered tab pane config type
YhTabPanePropsTab pane props type
YhTabPaneSlotsTab pane slots type
YhTabsInstanceTabs instance type
YhTabPaneInstanceTab pane instance type

YhTabPaneConfig Object Shape

YhTabs uses the following pane config shape for internal registration and event payloads. The source code normalizes name to string when a pane is registered.

ts
interface YhTabPaneConfig {
  name: string
  label: string
  disabled?: boolean
  closable?: boolean
  lazy?: boolean
  icon?: string
}

Theme Variables

YhTabs and YhTabPane support themeOverrides and consume the following dedicated CSS variables.

VariableDescriptionDefault
--yh-tabs-header-heightNavigation bar height40px
--yh-tabs-active-colorActive text and indicator colorvar(--yh-color-primary)
--yh-tabs-text-colorDefault tab text colorvar(--yh-text-color-primary)
--yh-tabs-disabled-colorDisabled tab text colorvar(--yh-text-color-disabled)
--yh-tabs-border-colorBorder colorvar(--yh-border-color-light)
--yh-tabs-indicator-widthDefault line indicator width40px
--yh-tabs-indicator-heightDefault vertical indicator height20px

Released under the MIT License.