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 (