From f8c130d0cb0afed435d3a19f933cbf7c80ad9d6f Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 19 Nov 2019 20:49:10 +0800 Subject: [PATCH] feat(Tab): add title-style prop (#5048) --- src/dropdown-item/index.js | 1 + src/tab/README.md | 1 + src/tab/README.zh-CN.md | 1 + src/tab/demo/index.vue | 72 +++++++------------------------------- src/tab/index.js | 1 + src/tab/test/index.spec.js | 12 +++++++ src/tabs/index.js | 1 + 7 files changed, 30 insertions(+), 59 deletions(-) diff --git a/src/dropdown-item/index.js b/src/dropdown-item/index.js index ccfa6c48b..53c122c8b 100644 --- a/src/dropdown-item/index.js +++ b/src/dropdown-item/index.js @@ -64,6 +64,7 @@ export default createComponent({ }, onClickWrapper(event) { + // prevent being identified as clicking outside and closed when use get-contaienr if (this.getContainer) { event.stopPropagation(); } diff --git a/src/tab/README.md b/src/tab/README.md index aa695859e..d03191d8d 100644 --- a/src/tab/README.md +++ b/src/tab/README.md @@ -200,6 +200,7 @@ In swipeable mode, you can switch tabs with swipe gestrue in the content |------|------|------|------|------| | name | Identifier | *string \| number* | Index of tab | - | | title | Title | *string* | - | - | +| title-style | Custom title style | *any* | - | 2.2.14 | | disabled | Whether to disable tab | *boolean* | `false` | - | | url | Link | *string* | - | 2.2.1 | | to | Target route of the link, same as to of vue-router | *string \| object* | - | 2.2.1 | diff --git a/src/tab/README.zh-CN.md b/src/tab/README.zh-CN.md index 97f1dd0e8..93e81a8c6 100644 --- a/src/tab/README.zh-CN.md +++ b/src/tab/README.zh-CN.md @@ -204,6 +204,7 @@ export default { |------|------|------|------|------| | name | 标签名称,作为匹配的标识符 | *string \| number* | 标签的索引值 | 2.0.6 | | title | 标题 | *string* | - | - | +| title-style | 自定义标题样式 | *any* | - | 2.2.14 | | disabled | 是否禁用标签 | *boolean* | `false` | - | | url | 点击后跳转的链接地址 | *string* | - | 2.2.1 | | to | 点击后跳转的目标路由对象,同 vue-router 的 [to 属性](https://router.vuejs.org/zh/api/#to) | *string \| object* | - | 2.2.1 | diff --git a/src/tab/demo/index.vue b/src/tab/demo/index.vue index faeb58930..9bd3c8d3c 100644 --- a/src/tab/demo/index.vue +++ b/src/tab/demo/index.vue @@ -2,11 +2,7 @@ - + {{ $t('content') }} {{ index }} @@ -14,22 +10,13 @@ - + {{ $t('content') }} 1 - + {{ $t('content') }} 2 - + {{ $t('content') }} 3 @@ -37,11 +24,7 @@ - + {{ $t('content') }} {{ index }} @@ -62,11 +45,7 @@ - + {{ $t('content') }} {{ index }} @@ -74,26 +53,15 @@ - + {{ $t('content') }} {{ index }} - - + + {{ $t('content') }} {{ index }} @@ -101,10 +69,7 @@ - + @@ -115,26 +80,15 @@ - + {{ $t('content') }} {{ index }} - - + + {{ $t('content') }} {{ index }} diff --git a/src/tab/index.js b/src/tab/index.js index 15996025d..94426e12a 100644 --- a/src/tab/index.js +++ b/src/tab/index.js @@ -11,6 +11,7 @@ export default createComponent({ ...routeProps, name: [Number, String], title: String, + titleStyle: null, disabled: Boolean }, diff --git a/src/tab/test/index.spec.js b/src/tab/test/index.spec.js index 978918526..55f8f408c 100644 --- a/src/tab/test/index.spec.js +++ b/src/tab/test/index.spec.js @@ -227,3 +227,15 @@ test('set name to zero', async () => { tabs.at(1).trigger('click'); expect(onClick).toHaveBeenCalledWith(0, 'title2'); }); + +test('title-style prop', () => { + const wrapper = mount({ + template: ` + + Text + + ` + }); + + expect(wrapper.find('.van-tab').element.style.color).toEqual('red'); +}); diff --git a/src/tabs/index.js b/src/tabs/index.js index bf837cf5c..346743173 100644 --- a/src/tabs/index.js +++ b/src/tabs/index.js @@ -266,6 +266,7 @@ export default createComponent({ type={type} title={item.title} color={this.color} + style={item.titleStyle} isActive={index === this.currentIndex} ellipsis={ellipsis} disabled={item.disabled}