Select: remove blur emit after soft focus (#10822)

pull/10823/head
杨奕 2018-04-21 16:39:48 +08:00 committed by GitHub
parent 1d33bae558
commit 9c058fbf7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 9 deletions

View File

@ -124,7 +124,7 @@
selectOptionClick() {
if (this.disabled !== true && this.groupDisabled !== true) {
this.dispatch('ElSelect', 'handleOptionClick', this);
this.dispatch('ElSelect', 'handleOptionClick', [this, true]);
}
},

View File

@ -78,7 +78,7 @@
:auto-complete="autoComplete"
:size="selectSize"
:disabled="selectDisabled"
:readonly="!filterable || multiple || !visible"
:readonly="!filterable || multiple"
:validate-event="false"
:class="{ 'is-focus': visible }"
@focus="handleFocus"
@ -312,7 +312,8 @@
inputHovering: false,
currentPlaceholder: '',
menuVisibleOnFocus: false,
isOnComposition: false
isOnComposition: false,
isSilentBlur: false
};
},
@ -565,7 +566,13 @@
},
handleBlur(event) {
setTimeout(() => {
if (this.isSilentBlur) {
this.isSilentBlur = false;
} else {
this.$emit('blur', event);
}
}, 50);
this.softFocus = false;
},
@ -652,7 +659,7 @@
}, 300);
},
handleOptionSelect(option) {
handleOptionSelect(option, byClick) {
if (this.multiple) {
const value = this.value.slice();
const optionIndex = this.getValueIndex(value, option.value);
@ -674,10 +681,11 @@
this.emitChange(option.value);
this.visible = false;
}
this.$nextTick(() => {
if (this.visible) return;
this.scrollToOption(option);
this.isSilentBlur = byClick;
this.setSoftFocus();
if (this.visible) return;
this.$nextTick(() => {
this.scrollToOption(option);
});
},

View File

@ -663,11 +663,11 @@ describe('Select', () => {
vm.$el.querySelector('input').focus();
vm.$el.querySelector('input').blur();
vm.$nextTick(_ => {
setTimeout(_ => {
expect(spyFocus.calledOnce).to.be.true;
expect(spyBlur.calledOnce).to.be.true;
done();
});
}, 100);
});
it('should return focus to input inside select after option select', done => {