JGuang

Tabs

Tabs · Ant Design

Preview
npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Tabs

Tabs make it easy to explore and switch between different views.

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

  • Basic · basic

  • Disabled · disabled

  • Centered · centered

  • Icon · icon

  • Indicator · custom-indicator

  • Slide · slide

  • Extra content · extra

  • Size · size

  • Placement · placement

  • Custom Popup Search · popupRender-Search

  • Card type tab · card

  • Add & close tab · editable-card

  • Customized trigger of new tab · custom-add-trigger

  • Customized bar of tab · custom-tab-bar

  • Draggable Tabs · custom-tab-bar-node

  • Custom semantic dom styling · style-class

API

Common props ref:Common props

Tabs

PropertyDescriptionTypeDefaultVersionGlobal Config
activeKeyCurrent TabPane's keystring-×
addIconCustomize add icon, only works with type="editable-card"ReactNode<PlusOutlined />4.4.05.14.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>-6.0.0
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.05.13.0
itemsConfigure tab contentTabItemType[]4.23.0×
moreCustomize the collapse menuMoreProps{ icon: <EllipsisOutlined /> , trigger: 'hover' }more.icon: 5.17.0
removeIconThe custom icon of remove, only works with type="editable-card"ReactNode<CloseOutlined />5.15.05.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>-6.0.0
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 tabs, please use tabPlacement insteadtop | right | bottom | lefttop×
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-
popupRenderCustomize the dropdown menu render(menu: ReactElement, info: { restTabs: Tab[], onClose: () => void }) => ReactElement-6.6.0
DropdownPropsSupport other Dropdown props

Semantic DOM

Semantic nodeNative descriptionVersion
rootRoot element with basic tab container styles, layout and direction control—
headerHeader element with tab navigation header layout, background, borders and other styles—
itemItem element with relative positioning, padding, colors, text ellipsis, border-radius, transitions and other tab item styles and interactive effects—
removeRemove button element with editable tab close button size, color, hover state and other interactive feedback styles6.4.0
indicatorIndicator element with indicator bar color, position, dimensions, transitions and other active state indication styles—
bodyBody element with tab panel container layout, animation and size control styles—
contentContent element with single tab panel layout, padding and other content display styles—
popup.rootPopup menu element with dropdown absolute positioning, z-index, display control, max-height, scrolling and other styles—

Semantic description source: vendor/components/tabs/demo/_semantic.tsx

Design Token

Types, inheritance and declarations retain the pinned native source. Defaults are computed by the native theme and may be overridden by ConfigProvider; this table does not invent static defaults.

TokenTypeNative description
zIndexPopupnumberz-index of dropdown menu
cardBgstringBackground color of card tab
cardHeightnumberHeight of card tab
cardHeightSMnumberHeight of small card tab
cardHeightLGnumberHeight of large card tab
cardPaddingstringPadding of card tab
cardPaddingSMstringPadding of small card tab
cardPaddingLGstringPadding of large card tab
titleFontSizenumberFont size of title
titleFontSizeLGnumberFont size of large title
titleFontSizeSMnumberFont size of small title
inkBarColorstringColor of indicator
horizontalMarginstringHorizontal margin of horizontal tab
horizontalItemGutternumberHorizontal gutter of horizontal tab
horizontalItemMarginstringHorizontal margin of horizontal tab item
horizontalItemMarginRTLstringHorizontal margin of horizontal tab item (RTL)
horizontalItemPaddingstringHorizontal padding of horizontal tab item
horizontalItemPaddingLGstringHorizontal padding of large horizontal tab item
horizontalItemPaddingSMstringHorizontal padding of small horizontal tab item
verticalItemPaddingstringVertical padding of vertical tab item
verticalItemMarginstringVertical margin of vertical tab item
itemColorstringText color of tab
itemActiveColorstringText color of active tab
itemHoverColorstringText color of hover tab
itemSelectedColorstringText color of selected tab
cardGutternumberGutter of card tab

Declaration source: vendor/components/tabs/style/index.ts

import { unit } from '@ant-design/cssinjs';

import type { CSSObject } from '@ant-design/cssinjs';

import { genFocusOutline, genFocusStyle, resetComponent, textEllipsis } from '../../style';

import { slideDownIn, slideDownOut, slideUpIn, slideUpOut } from '../../style/motion';

import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';

import { genStyleHooks, mergeToken } from '../../theme/internal';

import genMotionStyle from './motion';

export interface ComponentToken {
  /**
   * @desc 下拉菜单 z-index
   * @descEN z-index of dropdown menu
   */
  zIndexPopup: number;
  /**
   * @desc 卡片标签页背景色
   * @descEN Background color of card tab
   */
  cardBg: string;
  /**
   * @desc 卡片标签页高度
   * @descEN Height of card tab
   */
  cardHeight: number;
  /**
   * @desc 小尺寸卡片标签页高度
   * @descEN Height of small card tab
   */
  cardHeightSM: number;
  /**
   * @desc 大尺寸卡片标签页高度
   * @descEN Height of large card tab
   */
  cardHeightLG: number;
  /**
   * @desc 卡片标签页内间距
   * @descEN Padding of card tab
   */
  cardPadding: string;
  /**
   * @desc 小号卡片标签页内间距
   * @descEN Padding of small card tab
   */
  cardPaddingSM: string;
  /**
   * @desc 大号卡片标签页内间距
   * @descEN Padding of large card tab
   */
  cardPaddingLG: string;
  /**
   * @desc 标签页标题文本大小
   * @descEN Font size of title
   */
  titleFontSize: number;
  /**
   * @desc 大号标签页标题文本大小
   * @descEN Font size of large title
   */
  titleFontSizeLG: number;
  /**
   * @desc 小号标签页标题文本大小
   * @descEN Font size of small title
   */
  titleFontSizeSM: number;
  /**
   * @desc 指示条颜色
   * @descEN Color of indicator
   */
  inkBarColor: string;
  /**
   * @desc 横向标签页外间距
   * @descEN Horizontal margin of horizontal tab
   */
  horizontalMargin: string;
  /**
   * @desc 横向标签页标签间距
   * @descEN Horizontal gutter of horizontal tab
   */
  horizontalItemGutter: number;
  /**
   * @desc 横向标签页标签外间距
   * @descEN Horizontal margin of horizontal tab item
   */
  horizontalItemMargin: string;
  /**
   * @desc 横向标签页标签外间距(RTL)
   * @descEN Horizontal margin of horizontal tab item (RTL)
   */
  horizontalItemMarginRTL: string;
  /**
   * @desc 横向标签页标签内间距
   * @descEN Horizontal padding of horizontal tab item
   */
  horizontalItemPadding: string;
  /**
   * @desc 大号横向标签页标签内间距
   * @descEN Horizontal padding of large horizontal tab item
   */
  horizontalItemPaddingLG: string;
  /**
   * @desc 小号横向标签页标签内间距
   * @descEN Horizontal padding of small horizontal tab item
   */
  horizontalItemPaddingSM: string;
  /**
   * @desc 纵向标签页标签内间距
   * @descEN Vertical padding of vertical tab item
   */
  verticalItemPadding: string;
  /**
   * @desc 纵向标签页标签外间距
   * @descEN Vertical margin of vertical tab item
   */
  verticalItemMargin: string;
  /**
   * @desc 标签文本颜色
   * @descEN Text color of tab
   */
  itemColor: string;
  /**
   * @desc 标签激活态文本颜色
   * @descEN Text color of active tab
   */
  itemActiveColor: string;
  /**
   * @desc 标签悬浮态文本颜色
   * @descEN Text color of hover tab
   */
  itemHoverColor: string;
  /**
   * @desc 标签选中态文本颜色
   * @descEN Text color of selected tab
   */
  itemSelectedColor: string;
  /**
   * @desc 卡片标签间距
   * @descEN Gutter of card tab
   */
  cardGutter: number;
}

export interface TabsToken extends FullToken<'Tabs'> {
  tabsCardPadding: string;
  dropdownEdgeChildVerticalPadding: number;
  tabsNavWrapPseudoWidth: number;
  tabsDropdownHeight: number | string;
  tabsDropdownWidth: number | string;
  tabsHorizontalItemMargin: string;
  tabsHorizontalItemMarginRTL: string;
}

Shared native props

Tips: The following generic properties apply to most antd components; those not supported are described separately.

PropertyDescriptionTypeDefault
styleThe additional styleCSSProperties-
classNameThe additional css classstring-
rootClassNameClassName on the root elementstring-
autoFocusAuto focus when component mounted, only effective for focusable elements like forms, links, etc.booleanfalse

Install and reproduce an example

npm install antd@6.6.5 @ant-design/icons@6.3.4 dayjs@1.11.23

Use ConfigProvider and native App; configure dayjs locale separately. Each example lists its complete source files and additional pinned dependencies in View code. Example names select demos, not universal component props. See the resource setup guide for theme, locale and SSR.

Native type references

The source viewer includes unchanged native implementations and the following source declarations. Inherited types remain in their native packages. English source comments are preserved as code reference.

  • vendor/components/tabs/TabPane.ts
  • vendor/components/tabs/index.tsx
  • vendor/components/tabs/style/index.ts

Source and license

https://github.com/ant-design/ant-design/tree/4a39f54842eade4e565ab336ef6097cd7e723cdd

Original bilingual prose and executable examples are retained. Website-only embeds and token tables are expanded locally. Ant Design is MIT; separately listed dependency notices also apply. Upload previews block outbound requests and do not provide a backend.