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

Select: add test (#636)

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