Tabs

Tabs allow the user to switch between different views.

Tabs

Property

TypeDefault

Required

Description
classNameString

No

Customized class.
activeClsStringCustomized class for activating tabbar.
tabsArray 

Yes

tab data, including the tab title. The badge type badgeType includes dot and text, and is not displayed if the badgeType is not set. Badge text badgeText takes effect when the badgeType is text.
activeTabNumberYesIndex of the currently active tab.
showPlusBooleanfalse

No

Show the “+” icon or not.
onPlusClick() => {}

No

Callback when the “+” icon is clicked.
onTabClick(index: Number) => void

No

Callback when the tab is clicked.
onChange(index: Number) => void

No

Triggered when tab changes.
swipeableBooleantrue

No

If it is possible to switch contents by swiping.
durationNumber500(ms)

No

Duration of wiping animation in ms,   when the swipeable is true.
tabBarBackgroundColorString

No

tabBar background color.
tabBarActiveTextColorString

No

Active Tab text color of the tabBar.
tabBarInactiveTextColorString

No

Inactive Tab text color of the tabBar.
tabBarUnderlineColorString

No

tabBar underline color.
tabBarClsString

No

tabBar custom style class.

Tab-content

View content

PropertyDescriptionType
indexUnique index of list item.String

Example

copy
{
  "defaultTitle": "AntUI Component Library",
  "usingComponents": {
    "tabs": "mini-antui/es/tabs/index",
    "tab-content": "mini-antui/es/tabs/tab-content/index"
  }
}
copy
<view>
  <tabs
    tabs="{{tabs}}"
    showPlus="{{true}}"
    onTabClick="handleTabClick"
    onChange="handleTabChange"
    onPlusClick="handlePlusClick"
    activeTab="{{activeTab}}"
  >
    <block a:for="{{tabs}}">
      <tab-content key="{{index}}">
        <view class="tab-content">content of {{item.title}}</view>
      </tab-content>
    </block>
  </tabs>
</view>
copy
Page({
  data: {
    tabs: [
      {
        title: 'Option',
        badgeType: 'text',
        badgeText: '6',
      },
      {
        title: 'Option two',
        badgeType: 'dot',
      },
      { title: '3 Tab' },
      { title: '4 Tab' },
      { title: '5 Tab' },
    ],
    activeTab: 2,
  },
  handleTabClick({ index }) {
    this.setData({
      activeTab: index,
    });
  },
  handleTabChange({ index }) {
    this.setData({
      activeTab: index,
    });
  },
  handlePlusClick() {
    my.alert({
      content: 'plus clicked',
    });
  },
});
copy
.tab-content {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 300px;
}