Skip to content

Tabs Component ​

This component is a tabs component. When there are many tabs, it can be configured to scroll left and right; when there are few tabs, scrolling can be disabled. One feature of this component is that when configured in scroll mode, the active tab automatically moves to the center position of the component.

📌 Platform Compatibility ​

APP(vue)H5WeChat Mini ProgramAlipay Mini Program
✔✔✔✔

🏯 Basic Usage ​

html
<!-- Global usage -->
<hy-tabs :list="list"></hy-tabs>
ts
const list = [{ name: 'All' }, { name: 'Unredeemed' }, { name: 'Redeemed' }];

Displaying Badges ​

  • Set badge properties via badge; refer directly to the hy-badge component property configuration
html
<template>
    <hy-tabs :list="list"></hy-tabs>
</template>
<script setup>
    const list = [
        { title: 'All', badge: { isDot: true } },
        { title: 'Unredeemed', badge: { value: 5 } },
        { title: 'Redeemed' },
    ];
</script>

Custom Read Key ​

  • Customize the value to display via keyName
html
<template>
    <hy-tabs :list="list" keyName="title"></hy-tabs>
</template>
<script setup>
    const list = [
        { title: 'All', content: { value: 123 } },
        { title: 'Unredeemed' },
        { title: 'Redeemed' },
    ];
</script>

Custom Content via Swiper Slot ​

html
<template>
    <hy-tabs :list="statusTabs" @clickTabs="clickTabs" @change="change">
        <template #default="{record}">{{record.value}}</template>
    </hy-tabs>
</template>

<script setup>
    const statusTabs = [
        { name: 'All', content: { value: 123 } },
        { name: 'Unredeemed' },
        { name: 'Redeemed' },
    ];
    // Callback executed when a tab is clicked
    const clickTabs = () => {};
    // Callback function executed when the swiper is swiped
    const change = () => {};
</script>

Custom Swiper ​

html
<template>
    <hy-tabs :list="statusTabs" @clickTabs="clickTabs" @change="change">
        <template #main>
            <!--Custom content (without swiper)-->
        </template>
    </hy-tabs>
</template>

<script setup>
    const statusTabs = [{ name: 'All' }, { name: 'Unredeemed' }, { name: 'Redeemed' }];
    // Callback executed when a tab is clicked
    const clickTabs = () => {};
    // Callback function executed when the swiper is swiped
    const change = () => {};
</script>

API ​

Tabs Props ​

ParameterDescriptionTypeDefault
currentIndex of the currently selected tabnumber0
listArray of tabsTabsItemVo[]-
keyNameKey name to read from the list element objectsstringname
durationTime required for the slider to move once, in msnumber300
scrollableWhether the menu is scrollablebooleanfalse
lineWidthSlider length, default unit px for numbersstring|number20
lineHeightSlider height, default unit px for numbersstring|number3
lineColorSlider colorstring-
lineBgSizeSlider background display size, used when the slider background is set to an imagestring|numbercover
activeStyleStyle when a menu item is selectedCSSProperties-
inactiveStyleStyle when a menu item is not selectedCSSProperties-
itemStyleStyle of the menu itemstring-
badgePropsGlobal definition of badge props (badge in list takes higher priority)BadgeProps-
swiperHeightSwiper height, default unit px for numbersstring|numbercalc(100% - 44px)
isSwiperWhether to show content swiperbooleanfalse
iconStyleCustom style for the icon on the left side of the tabCSSProperties-
customStyleExternal styles to be appliedCSSProperties-
customClassCustom external class namestring-

Events ​

Event NameDescriptionCallback Parameters
clickTriggered when a tab is clickeditem: TabsItemVo, index: tab index
longPressTriggered when a tab is long-presseditem: TabsItemVo, index: tab index
changeTriggered when the tab index changesitem: TabsItemVo, index: tab index

Slots ​

Slot NameDescriptionReceived Values
defaultCustom content value for the swiperrecord: TabsItemVo, index: index
leftSlot on the left side of the whole component-
iconIcon of the tabsrecord: TabsItemVo, index: index
contentContent of the tabsrecord: TabsItemVo, index: index
rightSlot on the right side of the whole component-
mainCustom replacement for the bottom swiper-

Typings ​

Type Description
ts
export interface TabsItemVo {
    /**
     * Tab name
     * */
    name: string;
    /**
     * Props received by the badge
     * */
    badge?: HyBadgeProps;
    /**
     * Whether disabled
     * */
    disabled?: boolean;
    /**
     * Swiper content value
     * */
    content?: any;
    [key: string]: any;
}

CSS Variables ​

Variable NameDescriptionDefault
--hy-tabs-item-heightOption height44px
--hy-tabs-item-paddingOption padding0 11px
--hy-tabs-font-sizeFont size15px
--hy-tabs-line-widthUnderline width30px
--hy-tabs-line-heightUnderline height3px
--hy-tabs-text-colorDefault tab colorFollows --hy-text-color
--hy-tabs-text-active-colorActive tab colorFollows --hy-text-color
--hy-tabs-line-radiusUnderline border radiusFollows --hy-radius-semicircle (100px)
12:33
battery