diff --git a/src/cascader/index.js b/src/cascader/index.js index 6343cd0bb..1419a3720 100644 --- a/src/cascader/index.js +++ b/src/cascader/index.js @@ -1,6 +1,7 @@ import { createNamespace } from '../utils'; import Tab from '../tab'; import Tabs from '../tabs'; +import Icon from '../icon'; const [createComponent, bem] = createNamespace('cascader'); @@ -47,12 +48,40 @@ export default createComponent({ { title: this.placeholder || this.t('placeholder'), options: this.options, + selected: null, }, ]; } }, - genHeader() { + onSelect(option, tabIndex) { + this.tabs[tabIndex].title = option.text; + this.tabs[tabIndex].selected = option.value; + + if (this.tabs.length > tabIndex + 1) { + this.tabs = this.tabs.slice(0, tabIndex + 1); + } + + if (option.children) { + const nextTab = { + title: this.placeholder || this.t('placeholder'), + options: option.children, + selected: null, + }; + + if (this.tabs[tabIndex + 1]) { + this.$set(this.tabs, tabIndex + 1, nextTab); + } else { + this.tabs.push(nextTab); + } + + this.$nextTick(() => { + this.activeTab++; + }); + } + }, + + renderHeader() { return (

{this.slots('title') || this.title}

@@ -60,23 +89,41 @@ export default createComponent({ ); }, - genTabs() { + renderOptions(options, selected, tabIndex) { return ( - - {this.tabs.map((item) => ( - {this.genOptions(item.options)} - ))} - + ); }, - genOptions(options) { + renderTabs() { return ( - + ); }, }, @@ -84,8 +131,8 @@ export default createComponent({ render() { return (
- {this.genHeader()} - {this.genTabs()} + {this.renderHeader()} + {this.renderTabs()}
); }, diff --git a/src/cascader/index.less b/src/cascader/index.less index f79e7c574..1d6051099 100644 --- a/src/cascader/index.less +++ b/src/cascader/index.less @@ -19,10 +19,6 @@ .van-tab { flex: none; padding: 0 10px; - - &--active { - color: #969799; - } } &.van-tabs--line .van-tabs__wrap { @@ -31,19 +27,42 @@ } } + &__tab-title { + color: @gray-8; + font-weight: @font-weight-bold; + + &--unselected { + color: @gray-6; + } + } + &__option { - padding: 10px 16px; - font-size: 14px; - line-height: 20px; + display: flex; + align-items: center; + justify-content: space-between; + padding: 10px @padding-md; + font-size: @font-size-md; + line-height: @line-height-md; &:active { background-color: @active-color; } + + &--selected { + color: @red; + } + } + + &__selected-icon { + color: @red; + font-size: 18px; } &__options { box-sizing: border-box; height: 384px; padding-top: 6px; + overflow-y: auto; + -webkit-overflow-scrolling: touch; } } diff --git a/src/tab/README.md b/src/tab/README.md index 4a79c1c93..7beba24a9 100644 --- a/src/tab/README.md +++ b/src/tab/README.md @@ -252,6 +252,7 @@ export default { | to | Target route of the link, same as to of vue-router | _string \| object_ | - | | replace | If true, the navigation will not leave a history record | _boolean_ | `false` | | title-style | Custom title style | _any_ | - | +| title-class | Custom title class name | _any_ | - | ### Tabs Events diff --git a/src/tab/README.zh-CN.md b/src/tab/README.zh-CN.md index 815346c0c..8dfe33b66 100644 --- a/src/tab/README.zh-CN.md +++ b/src/tab/README.zh-CN.md @@ -260,6 +260,7 @@ export default { | to | 点击后跳转的目标路由对象,同 vue-router 的 [to 属性](https://router.vuejs.org/zh/api/#to) | _string \| object_ | - | | replace | 是否在跳转时替换当前页面历史 | _boolean_ | `false` | | title-style | 自定义标题样式 | _any_ | - | +| title-class | 自定义标题类名 | _any_ | - | ### Tabs Events diff --git a/src/tab/index.js b/src/tab/index.js index 73e3c0e18..077f3ec0c 100644 --- a/src/tab/index.js +++ b/src/tab/index.js @@ -16,6 +16,7 @@ export default createComponent({ badge: [Number, String], title: String, titleStyle: null, + titleClass: null, disabled: Boolean, }, diff --git a/src/tabs/index.js b/src/tabs/index.js index 491cea15c..1db2d510b 100644 --- a/src/tabs/index.js +++ b/src/tabs/index.js @@ -372,6 +372,7 @@ export default createComponent({ title={item.title} color={this.color} style={item.titleStyle} + class={item.titleClass} isActive={index === this.currentIndex} disabled={item.disabled} scrollable={scrollable}