Back to Ant Design

Tabs

components/tabs/index.en-US.md

6.3.76.2 KB
Original Source

When To Use

Ant Design has 3 types of Tabs for different situations.

  • Card Tabs: for managing too many closeable views.
  • Normal Tabs: for functional aspects of a page.
  • Radio.Button: for secondary tabs.

Examples

<!-- prettier-ignore -->

<code src="./demo/basic.tsx">Basic</code> <code src="./demo/disabled.tsx">Disabled</code> <code src="./demo/centered.tsx">Centered</code> <code src="./demo/icon.tsx">Icon</code> <code src="./demo/custom-indicator.tsx">Indicator</code> <code src="./demo/slide.tsx">Slide</code> <code src="./demo/extra.tsx">Extra content</code> <code src="./demo/size.tsx">Size</code> <code src="./demo/placement.tsx">Placement</code> <code src="./demo/card.tsx">Card type tab</code> <code src="./demo/editable-card.tsx">Add & close tab</code> <code src="./demo/card-top.tsx" compact background="grey" debug>Container of card type Tab</code> <code src="./demo/custom-add-trigger.tsx">Customized trigger of new tab</code> <code src="./demo/custom-tab-bar.tsx">Customized bar of tab</code> <code src="./demo/custom-tab-bar-node.tsx">Draggable Tabs</code> <code src="./demo/style-class.tsx" version="6.0.0">Custom semantic dom styling</code> <code src="./demo/animated.tsx" debug>Animated</code> <code src="./demo/nest.tsx" debug>Nest</code> <code src="./demo/component-token.tsx" debug>component Token</code>

API

Common props ref:Common props

Tabs

<!-- prettier-ignore -->
PropertyDescriptionTypeDefaultVersion
activeKeyCurrent TabPane's keystring-
addIconCustomize add icon, only works with type="editable-card"ReactNode<PlusOutlined />4.4.0
animatedWhether to change tabs with animation.boolean | { inkBar: boolean, tabPane: boolean }{ inkBar: true, tabPane: false }
centeredCenters tabsbooleanfalse4.4.0
classNamesCustomize class for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, string> | (info: { props })=> Record<SemanticDOM, string>(#semantic-dom)-
defaultActiveKeyInitial active TabPane's key, if activeKey is not setstringThe key of first tab
hideAddHide plus icon or not. Only works while type="editable-card"booleanfalse
indicatorCustomize size and align of indicator{ size?: number | (origin: number) => number; align: start | center | end; }-5.13.0
itemsConfigure tab contentTabItemType[]4.23.0
moreCustomize the collapse menuMoreProps{ icon: <EllipsisOutlined /> , trigger: 'hover' }
removeIconThe custom icon of remove, only works with type="editable-card"ReactNode<CloseOutlined />5.15.0
popupClassNameclassName for more dropdown, please use classNames.popup insteadstring-4.21.0
renderTabBarReplace the TabBar(props: DefaultTabBarProps, DefaultTabBar: React.ComponentClass) => React.ReactElement-
sizePreset tab bar sizelarge | medium | smallmedium
stylesCustomize inline style for each semantic structure inside the component. Supports object or function.Record<SemanticDOM, CSSProperties> | (info: { props })=> Record<SemanticDOM, CSSProperties>-
tabBarExtraContentExtra content in tab barReactNode | {left?: ReactNode, right?: ReactNode}-object: 4.6.0
tabBarGutterThe gap between tabsnumber-
tabBarStyleTab bar style objectCSSProperties-
tabPlacementPlacement of tabstop | end | bottom | starttop
tabPositionPosition of tabstop | right | bottom | left, please use tabPlacement insteadtop
destroyInactiveTabPaneWhether destroy inactive TabPane when change tab, use destroyOnHidden insteadbooleanfalse
destroyOnHiddenWhether destroy inactive TabPane when change tabbooleanfalse5.25.0
typeBasic style of tabsline | card | editable-cardline
onChangeCallback executed when active tab is changed(activeKey: string) => void-
onEditCallback executed when tab is added or removed. Only works while type="editable-card"(action === 'add' ? event : targetKey, action) => void-
onTabClickCallback executed when tab is clicked(key: string, event: MouseEvent) => void-
onTabScrollTrigger when tab scroll({ direction: left | right | top | bottom }) => void-4.3.0

More option at @rc-component/tabs

TabItemType

PropertyDescriptionTypeDefaultVersion
closeIconCustomize close icon in TabPane's head. Only works while type="editable-card". 5.7.0: close button will be hidden when setting to null or falseReactNode-
destroyInactiveTabPaneWhether destroy inactive TabPane when change tab, use destroyOnHidden insteadbooleanfalse5.11.0
destroyOnHiddenWhether destroy inactive TabPane when change tabbooleanfalse5.25.0
disabledSet TabPane disabledbooleanfalse
forceRenderForced render of content in tabs, not lazy render after clicking on tabsbooleanfalse
keyTabPane's keystring-
labelTab header text elementReactNode-
iconTab header icon elementReactNode-5.12.0
childrenTab content elementReactNode-
closableWhether a close (x) button is visible, Only works while type="editable-card"booleantrue

MoreProps

PropertyDescriptionTypeDefaultVersion
iconThe custom iconReactNode-
DropdownProps

Semantic DOM

<code src="./demo/_semantic.tsx" simplify="true"></code>

Design Token

<ComponentTokenTable component="Tabs"></ComponentTokenTable>