feat(Tab): add title-style prop (#5048)

This commit is contained in:
neverland 2019-11-19 20:49:10 +08:00 committed by GitHub
parent dbd0951b30
commit f8c130d0cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 59 deletions

View File

@ -64,6 +64,7 @@ export default createComponent({
}, },
onClickWrapper(event) { onClickWrapper(event) {
// prevent being identified as clicking outside and closed when use get-contaienr
if (this.getContainer) { if (this.getContainer) {
event.stopPropagation(); event.stopPropagation();
} }

View File

@ -200,6 +200,7 @@ In swipeable mode, you can switch tabs with swipe gestrue in the content
|------|------|------|------|------| |------|------|------|------|------|
| name | Identifier | *string \| number* | Index of tab | - | | name | Identifier | *string \| number* | Index of tab | - |
| title | Title | *string* | - | - | | title | Title | *string* | - | - |
| title-style | Custom title style | *any* | - | 2.2.14 |
| disabled | Whether to disable tab | *boolean* | `false` | - | | disabled | Whether to disable tab | *boolean* | `false` | - |
| url | Link | *string* | - | 2.2.1 | | url | Link | *string* | - | 2.2.1 |
| to | Target route of the link, same as to of vue-router | *string \| object* | - | 2.2.1 | | to | Target route of the link, same as to of vue-router | *string \| object* | - | 2.2.1 |

View File

@ -204,6 +204,7 @@ export default {
|------|------|------|------|------| |------|------|------|------|------|
| name | 标签名称,作为匹配的标识符 | *string \| number* | 标签的索引值 | 2.0.6 | | name | 标签名称,作为匹配的标识符 | *string \| number* | 标签的索引值 | 2.0.6 |
| title | 标题 | *string* | - | - | | title | 标题 | *string* | - | - |
| title-style | 自定义标题样式 | *any* | - | 2.2.14 |
| disabled | 是否禁用标签 | *boolean* | `false` | - | | disabled | 是否禁用标签 | *boolean* | `false` | - |
| url | 点击后跳转的链接地址 | *string* | - | 2.2.1 | | url | 点击后跳转的链接地址 | *string* | - | 2.2.1 |
| to | 点击后跳转的目标路由对象,同 vue-router 的 [to 属性](https://router.vuejs.org/zh/api/#to) | *string \| object* | - | 2.2.1 | | to | 点击后跳转的目标路由对象,同 vue-router 的 [to 属性](https://router.vuejs.org/zh/api/#to) | *string \| object* | - | 2.2.1 |

View File

@ -2,11 +2,7 @@
<demo-section> <demo-section>
<demo-block :title="$t('basicUsage')"> <demo-block :title="$t('basicUsage')">
<van-tabs v-model="active"> <van-tabs v-model="active">
<van-tab <van-tab :title="$t('tab') + index" v-for="index in tabs" :key="index">
:title="$t('tab') + index"
v-for="index in tabs"
:key="index"
>
{{ $t('content') }} {{ index }} {{ $t('content') }} {{ index }}
</van-tab> </van-tab>
</van-tabs> </van-tabs>
@ -14,22 +10,13 @@
<demo-block :title="$t('matchByName')"> <demo-block :title="$t('matchByName')">
<van-tabs v-model="activeName"> <van-tabs v-model="activeName">
<van-tab <van-tab name="a" :title="$t('tab') + 1">
name="a"
:title="$t('tab') + 1"
>
{{ $t('content') }} 1 {{ $t('content') }} 1
</van-tab> </van-tab>
<van-tab <van-tab name="b" :title="$t('tab') + 2">
name="b"
:title="$t('tab') + 2"
>
{{ $t('content') }} 2 {{ $t('content') }} 2
</van-tab> </van-tab>
<van-tab <van-tab name="c" :title="$t('tab') + 3">
name="c"
:title="$t('tab') + 3"
>
{{ $t('content') }} 3 {{ $t('content') }} 3
</van-tab> </van-tab>
</van-tabs> </van-tabs>
@ -37,11 +24,7 @@
<demo-block :title="$t('title2')"> <demo-block :title="$t('title2')">
<van-tabs> <van-tabs>
<van-tab <van-tab v-for="index in 8" :title="$t('tab') + index" :key="index">
v-for="index in 8"
:title="$t('tab') + index"
:key="index"
>
{{ $t('content') }} {{ index }} {{ $t('content') }} {{ index }}
</van-tab> </van-tab>
</van-tabs> </van-tabs>
@ -62,11 +45,7 @@
<demo-block :title="$t('title4')"> <demo-block :title="$t('title4')">
<van-tabs type="card"> <van-tabs type="card">
<van-tab <van-tab v-for="index in 3" :title="$t('tab') + index" :key="index">
v-for="index in 3"
:title="$t('tab') + index"
:key="index"
>
{{ $t('content') }} {{ index }} {{ $t('content') }} {{ index }}
</van-tab> </van-tab>
</van-tabs> </van-tabs>
@ -74,26 +53,15 @@
<demo-block :title="$t('title5')"> <demo-block :title="$t('title5')">
<van-tabs @click="onClick"> <van-tabs @click="onClick">
<van-tab <van-tab v-for="index in 2" :title="$t('tab') + index" :key="index">
v-for="index in 2"
:title="$t('tab') + index"
:key="index"
>
{{ $t('content') }} {{ index }} {{ $t('content') }} {{ index }}
</van-tab> </van-tab>
</van-tabs> </van-tabs>
</demo-block> </demo-block>
<demo-block :title="$t('title6')"> <demo-block :title="$t('title6')">
<van-tabs <van-tabs :active="active" sticky>
:active="active" <van-tab :title="$t('tab') + index" v-for="index in tabs" :key="index">
sticky
>
<van-tab
:title="$t('tab') + index"
v-for="index in tabs"
:key="index"
>
{{ $t('content') }} {{ index }} {{ $t('content') }} {{ index }}
</van-tab> </van-tab>
</van-tabs> </van-tabs>
@ -101,10 +69,7 @@
<demo-block v-if="!$attrs.weapp" :title="$t('title7')"> <demo-block v-if="!$attrs.weapp" :title="$t('title7')">
<van-tabs :active="active"> <van-tabs :active="active">
<van-tab <van-tab v-for="index in 2" :key="index">
v-for="index in 2"
:key="index"
>
<template #title> <template #title>
<van-icon name="more-o" />{{ $t('tab') }} <van-icon name="more-o" />{{ $t('tab') }}
</template> </template>
@ -115,26 +80,15 @@
<demo-block :title="$t('title8')"> <demo-block :title="$t('title8')">
<van-tabs animated> <van-tabs animated>
<van-tab <van-tab :title="$t('tab') + index" v-for="index in tabs" :key="index">
:title="$t('tab') + index"
v-for="index in tabs"
:key="index"
>
{{ $t('content') }} {{ index }} {{ $t('content') }} {{ index }}
</van-tab> </van-tab>
</van-tabs> </van-tabs>
</demo-block> </demo-block>
<demo-block :title="$t('title9')"> <demo-block :title="$t('title9')">
<van-tabs <van-tabs :active="active" swipeable>
:active="active" <van-tab :title="$t('tab') + index" v-for="index in tabs" :key="index">
swipeable
>
<van-tab
:title="$t('tab') + index"
v-for="index in tabs"
:key="index"
>
{{ $t('content') }} {{ index }} {{ $t('content') }} {{ index }}
</van-tab> </van-tab>
</van-tabs> </van-tabs>

View File

@ -11,6 +11,7 @@ export default createComponent({
...routeProps, ...routeProps,
name: [Number, String], name: [Number, String],
title: String, title: String,
titleStyle: null,
disabled: Boolean disabled: Boolean
}, },

View File

@ -227,3 +227,15 @@ test('set name to zero', async () => {
tabs.at(1).trigger('click'); tabs.at(1).trigger('click');
expect(onClick).toHaveBeenCalledWith(0, 'title2'); expect(onClick).toHaveBeenCalledWith(0, 'title2');
}); });
test('title-style prop', () => {
const wrapper = mount({
template: `
<van-tabs>
<van-tab title="title1" title-style="color: red;">Text</van-tab>
</van-tabs>
`
});
expect(wrapper.find('.van-tab').element.style.color).toEqual('red');
});

View File

@ -266,6 +266,7 @@ export default createComponent({
type={type} type={type}
title={item.title} title={item.title}
color={this.color} color={this.color}
style={item.titleStyle}
isActive={index === this.currentIndex} isActive={index === this.currentIndex}
ellipsis={ellipsis} ellipsis={ellipsis}
disabled={item.disabled} disabled={item.disabled}