Tabs

Tabs allow the user to switch between different views.

Tabs

Attribute NameDescriptionTypeDefaultMandatory
classNameCustom classStringfalse
activeClsCustomized class for activating   tabbarString
tabstab 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.Arraytrue
activeTabIndex of the currently active tabNumbertrue
showPlusShow the “+” icon or notBooleanfalsefalse
onPlusClickCallback when the “+” icon is   clicked() => {}false
onTabClickCallback when the tab is clicked(index: Number) => voidfalse
onChangeTriggered when tab changes(index: Number) => voidfalse
swipeableIf it is possible to switch contents   by swipingBooleantruefalse
durationDuration of wiping animation in ms,   when the swipeable is trueNumber500(ms)false
tabBarBackgroundColortabBar background colorStringfalse
tabBarActiveTextColorActive Tab text color of the tabBarStringfalse
tabBarInactiveTextColorInactive Tab text color of the   tabBarStringfalse
tabBarUnderlineColortabBar underline colorStringfalse
tabBarClstabBar custom style classStringfalse

Tab-content

View content

Attribute NameDescriptionTypeDefaultMandatory
indexUnique index of list itemString

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;
}