Back to Element Plus

Tabs

docs/en-US/component/tabs.md

2.13.79.5 KB
Original Source

Tabs

Divide data collections which are related yet belong to different types.

Basic usage

Basic and concise tabs.

:::demo Tabs provide a selective card functionality. By default the first tab is selected as active, and you can activate any tab by setting the value attribute.

tabs/basic

:::

Card Style

Tabs styled as cards.

:::demo Set type to card can get a card-styled tab.

tabs/card-style

:::

Border card

Border card tabs.

:::demo Set type to border-card.

tabs/border-card

:::

Tab position

You can use tab-position attribute to set the tab's position.

:::demo You can choose from four directions: tabPosition="left|right|top|bottom"

tabs/tab-position

:::

Custom Tab

You can use named slot to customize the tab label content.

:::demo

tabs/custom-tab

:::

Add & close tab

Only card type Tabs support addable & closeable.

:::demo

tabs/dynamic-tabs

:::

Customized add button icon ^(2.4.0)

:::demo

tabs/customized-add-button-icon

:::

Customized trigger button of new tab

:::demo

tabs/customized-trigger

:::

Default value ^(2.11.9)

:::demo

tabs/default-value

:::

Tabs API

Tabs Attributes

NameDescriptionTypeDefault
model-value / v-modelbinding value, name of the selected tab, the default value is the name of first tab^[string] / ^[number]
default-value ^(2.11.9)The value of the tab that should be active when initially rendered. (avoid initial transition)^[string] / ^[number]
typetype of Tab^[enum]'' | 'card' | 'border-card'''
closablewhether Tab is closable^[boolean]false
addablewhether Tab is addable^[boolean]false
editablewhether Tab is addable and closable^[boolean]false
tab-positionposition of tabs^[enum]'top' | 'right' | 'bottom' | 'left'top
stretchwhether width of tab automatically fits its container^[boolean]false
before-leavehook function before switching tab. If false is returned or a Promise is returned and then is rejected, switching will be prevented^[Function](activeName: TabPaneName, oldActiveName: TabPaneName) => Awaitable<void | boolean>() => true
tabindex ^(2.11.7)tabs tabindex^[string] / ^[number]0

Tabs Events

NameDescriptionParameters
tab-clicktriggers when a tab is clicked^[Function](pane: TabsPaneContext, ev: Event) => void
tab-changetriggers when activeName is changed^[Function](name: TabPaneName) => void
tab-removetriggers when tab-remove button is clicked^[Function](name: TabPaneName) => void
tab-addtriggers when tab-add button is clicked^[Function]() => void
edittriggers when tab-add button or tab-remove is clicked^[Function](paneName: TabPaneName | undefined, action: 'remove' | 'add') => void

Tabs Slots

NameDescriptionSubtags
defaultcustomize default contentTab-pane
add-icon ^(2.5.4)customize add button icon
addIcon ^(2.4.0) ^(deprecated)customize add button icon

Tabs Exposes

NameDescriptionType
currentNamecurrent active pane name^[object]Ref<TabPaneName>
tabNavRef ^(2.9.10)tab-nav component instance^[object]Ref<TabNavInstance | undefined>

Tab-nav API

Tab-nav Exposes

NameDescriptionType
scrollToActiveTabscroll to the active tab^[Function]() => Promise<void>
removeFocusremove focus status^[Function]() => boolean
tabListRef ^(2.9.10)el_tabs__nav html element^[object]Ref<HTMLDivElement | undefined>
tabBarRef ^(2.9.10)el_tabs__nav bar instance^[object]Ref<TabBarInstance | undefined>

Tab-bar API

Tab-bar Exposes

NameDescriptionType
ref ^(2.9.10)tab root html element^[object]Ref<HTMLDivElement | undefined>
update ^(2.9.10)method to manually update tab bar style, return the updated style^[Function]() => CSSProperties

Tab-pane API

Tab-pane Attributes

NameDescriptionTypeDefault
labeltitle of the tab^[string]''
disabledwhether Tab is disabled^[boolean]false
nameidentifier corresponding to the name of Tabs, representing the alias of the tab-pane, the default is ordinal number of the tab-pane in the sequence, e.g. the first tab-pane is '0'^[string] / ^[number]
closablewhether Tab is closable^[boolean]false
lazywhether Tab is lazily rendered^[boolean]false

Tab-pane Slots

NameDescription
defaultTab-pane's content
labelTab-pane's label

FAQ

How to use sortable/draggable tabs ?

We exposed the necessary information to implement it yourself. You can use a native way to do it, demo. Or using SortableJs, demo.