JGuang

Tabs

Tabs · Ant Design Mobile

Preview
npm install antd-mobile@5.43.0

Tabs

Navigate between content groups.

Install

npm install antd-mobile@5.43.0

antd-mobile is for mobile web, not React Native or Mini Programs. React 19 projects must register createRoot with unstableSetRender at the entry, or imperative APIs such as Toast and Dialog cannot render. Switch dark mode with <html data-prefers-color-scheme="dark">.

Examples come from the official Ant Design Mobile repository (MIT) at the commit published as npm 5.43.0. Presentation helpers such as DemoBlock are JGuang rewrites, not antd-mobile APIs.

Navigate between content groups.

When to Use

The current content needs to be divided into groups of the same hierarchical structure for content switching display, which is often used at the top of a form or list.

Demos

Tabs

Props

NameDescriptionTypeDefault
activeKeyThe key of the currently active tab panelstring | null-
activeLineModeActivate tab underline mode'auto' | 'full' | 'fixed''auto'
defaultActiveKeyThe initialized key of the selected panel, if the activeKey is not setstring | nullthe key of the 1st pannel
onChangeCallback when switching panel(key: string) => void-
stretchWhether stretch the tab headerbooleantrue
directionDocument layout direction'ltr' | 'rtl''ltr'

CSS Variables

NameDescriptionDefault
--active-line-border-radiusThe borderRadius of the active tab underlinevar(--active-line-height)
--active-line-colorThe color of the active tab underlinevar(--adm-color-primary)
--active-line-heightThe height of the active tab underline2px
--active-title-colorThe color of the active tab titlevar(--adm-color-primary)
--content-paddingPadding of the tab content12px
--fixed-active-line-widthThe width of the active tab underline. Only take effect when activeLineMode is 'fixed'.30px
--title-font-sizeFont size of the displayed text of the tab header17px

Tabs.Tab

NameDescriptionTypeDefault
destroyOnCloseDestroy dom when not visiblebooleanfalse
disabledWhether to disable the tabbooleanfalse
forceRenderWhether to render the DOM structure when hiddenbooleanfalse
keyCorresponding to activeKeystring-
titleThe displayed text of the tab headerReactNode-

FAQ

Does Tabs support sticky effect?

Yes, but Tabs doesn't have a property like sticky. You can add the CSS position: sticky to the outer container of Tabs to achieve the ceiling effect.

How does Tabs work with Swiper, PullToRefresh, and InfiniteScroll to implement a complex information flow interface?

You can refer to this demo.

About the type of Tabs.Tab key

React will convert the incoming key into string, the type of key only needs to match React.Key.