support tab disabled

This commit is contained in:
baiyaaaaa 2016-12-08 10:47:16 +08:00 committed by 杨奕
parent 658383ecae
commit 3d12579652
6 changed files with 41 additions and 2 deletions

View File

@ -143,4 +143,5 @@ Border card tabs.
|---------- |-------- |---------- |------------- |-------- | |---------- |-------- |---------- |------------- |-------- |
| label | title of the tab | string | — | — | | label | title of the tab | string | — | — |
| label-content | render function for tab title | Function(h) | - | - | | label-content | render function for tab title | Function(h) | - | - |
| disabled | whether Tab is disabled | boolean | - | false |
| name | identifier corresponding to the activeName of Tabs, representing the alias of the tab-pane | string | — | ordinal number of the tab-pane in the sequence, i.e. the first tab-pane is '1' | | name | identifier corresponding to the activeName of Tabs, representing the alias of the tab-pane | string | — | ordinal number of the tab-pane in the sequence, i.e. the first tab-pane is '1' |

View File

@ -138,4 +138,5 @@
|---------- |-------- |---------- |------------- |-------- | |---------- |-------- |---------- |------------- |-------- |
| label | 选项卡标题 | string | — | — | | label | 选项卡标题 | string | — | — |
| label-content | 选项卡的标题的渲染 Function | Function(h) | - | - | | label-content | 选项卡的标题的渲染 Function | Function(h) | - | - |
| disabled | 是否禁用 | boolean | - | false |
| name | 与选项卡 activeName 对应的标识符,表示选项卡别名 | string | — | 该选项卡在选项卡列表中的顺序值,如第一个选项卡则为'1' | | name | 与选项卡 activeName 对应的标识符,表示选项卡别名 | string | — | 该选项卡在选项卡列表中的顺序值,如第一个选项卡则为'1' |

View File

@ -6,7 +6,8 @@
label: String, label: String,
labelContent: Function, labelContent: Function,
name: String, name: String,
closable: Boolean closable: Boolean,
disabled: Boolean
}, },
data() { data() {

View File

@ -39,12 +39,21 @@
let nextChild = tabs[index]; let nextChild = tabs[index];
let prevChild = tabs[index - 1]; let prevChild = tabs[index - 1];
this.currentName = nextChild ? nextChild.index : prevChild ? prevChild.index : '-1'; while (prevChild && prevChild.disabled) {
prevChild = tabs[tabs.indexOf(prevChild) - 1];
}
this.currentName = nextChild
? nextChild.index
: prevChild
? prevChild.index
: '-1';
} }
this.$emit('tab-remove', tab); this.$emit('tab-remove', tab);
this.$forceUpdate(); this.$forceUpdate();
}, },
handleTabClick(tab, event) { handleTabClick(tab, event) {
if (tab.disabled) return;
this.currentName = tab.index; this.currentName = tab.index;
this.$emit('tab-click', tab, event); this.$emit('tab-click', tab, event);
}, },

View File

@ -59,6 +59,11 @@
color: #1f2d3d; color: #1f2d3d;
cursor: pointer; cursor: pointer;
} }
@when disabled {
color: var(--disabled-color-base);
cursor: default;
}
} }
@e content { @e content {
overflow: hidden; overflow: hidden;

View File

@ -241,4 +241,26 @@ describe('Tabs', () => {
done(); done();
}); });
}); });
it('disabled', done => {
vm = createVue({
template: `
<el-tabs type="card">
<el-tab-pane label="用户管理">A</el-tab-pane>
<el-tab-pane disabled label="配置管理" ref="disabled">B</el-tab-pane>
<el-tab-pane label="角色管理">C</el-tab-pane>
<el-tab-pane label="定时任务补偿">D</el-tab-pane>
</el-tabs>
`
}, true);
vm.$nextTick(_ => {
let tabList = vm.$el.querySelector('.el-tabs__header').children;
tabList[1].click();
vm.$nextTick(_ => {
expect(tabList[1].classList.contains('is-active')).to.not.true;
done();
});
});
});
}); });