Commit 2f0ba607 authored by 杨奕's avatar 杨奕 Committed by FuryBean

Select: add test (#636)

parent cfe8b895
......@@ -262,7 +262,7 @@
包含清空按钮,可将选择器清空为初始状态
:::demo 为`el-select`设置`clearable`属性,则可将选择器清空。需要注意的是,`clearable`属性仅使用于单选。
:::demo 为`el-select`设置`clearable`属性,则可将选择器清空。需要注意的是,`clearable`属性仅用于单选。
```html
<template>
<el-select v-model="value4" clearable>
......
......@@ -25,9 +25,15 @@
}
},
watch: {
disabled(val) {
this.broadcast('option', 'handleGroupDisabled', val);
}
},
mounted() {
if (this.disabled) {
this.broadcast('option', 'disableOptions');
this.broadcast('option', 'handleGroupDisabled', this.disabled);
}
}
};
......
......@@ -4,7 +4,7 @@
@click.stop="selectOptionClick"
class="el-select-dropdown__item"
v-show="queryPassed"
:class="{ 'selected': itemSelected, 'is-disabled': disabled, 'hover': parent.hoverIndex === index }">
:class="{ 'selected': itemSelected, 'is-disabled': disabled || groupDisabled, 'hover': parent.hoverIndex === index }">
<slot>
<span>{{ currentLabel }}</span>
</slot>
......@@ -39,13 +39,17 @@
data() {
return {
index: -1,
groupDisabled: false,
queryPassed: true,
hitState: false,
currentLabel: this.label
hitState: false
};
},
computed: {
currentLabel() {
return this.label || ((typeof this.value === 'string' || typeof this.value === 'number') ? this.value : '');
},
parent() {
let result = this.$parent;
while (!result.isSelect) {
......@@ -76,18 +80,18 @@
},
methods: {
disableOptions() {
this.disabled = true;
handleGroupDisabled(val) {
this.groupDisabled = val;
},
hoverItem() {
if (!this.disabled) {
if (!this.disabled && !this.groupDisabled) {
this.parent.hoverIndex = this.parent.options.indexOf(this);
}
},
selectOptionClick() {
if (this.disabled !== true) {
if (this.disabled !== true && this.groupDisabled !== true) {
this.dispatch('select', 'handleOptionClick', this);
}
},
......@@ -107,7 +111,6 @@
},
created() {
this.currentLabel = this.currentLabel || ((typeof this.value === 'string' || typeof this.value === 'number') ? this.value : '');
this.parent.options.push(this);
this.parent.optionsCount++;
this.parent.filteredOptionsCount++;
......@@ -118,7 +121,7 @@
}
this.$on('queryChange', this.queryChange);
this.$on('disableOptions', this.disableOptions);
this.$on('handleGroupDisabled', this.handleGroupDisabled);
this.$on('resetIndex', this.resetIndex);
},
......
......@@ -53,11 +53,11 @@
<transition name="md-fade-bottom" @after-leave="doDestroy">
<el-select-menu
ref="popper"
v-show="visible && nodataText !== false">
v-show="visible && emptyText !== false">
<ul class="el-select-dropdown__list" v-show="options.length > 0 && filteredOptionsCount > 0 && !loading">
<slot></slot>
</ul>
<p class="el-select-dropdown__nodata" v-if="nodataText">{{ nodataText }}</p>
<p class="el-select-dropdown__nodata" v-if="emptyText">{{ emptyText }}</p>
</el-select-menu>
</transition>
</div>
......@@ -106,7 +106,7 @@
return criteria;
},
nodataText() {
emptyText() {
if (this.loading) {
return '加载中';
} else {
......@@ -439,7 +439,9 @@
this.hoverIndex = 0;
}
this.resetScrollTop();
if (this.options[this.hoverIndex].disabled === true || !this.options[this.hoverIndex].queryPassed) {
if (this.options[this.hoverIndex].disabled === true ||
this.options[this.hoverIndex].groupDisabled === true ||
!this.options[this.hoverIndex].queryPassed) {
this.navigateOptions('next');
}
}
......@@ -449,7 +451,9 @@
this.hoverIndex = this.options.length - 1;
}
this.resetScrollTop();
if (this.options[this.hoverIndex].disabled === true || !this.options[this.hoverIndex].queryPassed) {
if (this.options[this.hoverIndex].disabled === true ||
this.options[this.hoverIndex].groupDisabled === true ||
!this.options[this.hoverIndex].queryPassed) {
this.navigateOptions('prev');
}
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment