Merge pull request #4598 from vincentfintend/fix-select-4273

fix select #4273
This commit is contained in:
Aresn 2018-09-29 10:15:40 +08:00 committed by GitHub
commit 171bc082f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -44,8 +44,6 @@
@on-input-focus="isFocused = true"
@on-input-blur="isFocused = false"
@on-clear="clearSingleSelect"
@on-keydown="handleFilterInputKeyDown"
/>
</slot>
</div>
@ -266,7 +264,7 @@
unchangedQuery: true,
hasExpectedValue: false,
preventRemoteCall: false,
filterQueryKeyDown: false, // #4273
filterQueryChange: false, // #4273
};
},
computed: {
@ -296,12 +294,6 @@
[`${prefixCls}-selection-focused`]: this.isFocused
};
},
queryStringMatchesSelectedOption(){
const selectedOptions = this.values[0];
if (!selectedOptions) return false;
const [query, label] = [this.query, selectedOptions.label].map(str => (str || '').trim());
return !this.multiple && this.unchangedQuery && query === label;
},
localeNotFoundText () {
if (typeof this.notFoundText === 'undefined') {
return this.t('i.select.noMatch');
@ -368,10 +360,6 @@
});
});
}
/**
* Not sure why use hasDefaultSelected #4273
* */
let hasDefaultSelected = slotOptions.some(option => this.query === option.key);
for (let option of slotOptions) {
const cOptions = option.componentOptions;
@ -395,7 +383,7 @@
if (cOptions.children.length > 0) selectOptions.push({...option});
} else {
// ignore option if not passing filter
if (!hasDefaultSelected || this.filterQueryKeyDown) {
if (this.filterQueryChange) {
const optionPassesFilter = this.filterable ? this.validateOption(cOptions) : option;
if (!optionPassesFilter) continue;
}
@ -405,8 +393,6 @@
}
}
this.filterQueryKeyDown = false;
return selectOptions;
},
flatOptions(){
@ -479,8 +465,6 @@
},
validateOption({children, elm, propsData}){
if (this.queryStringMatchesSelectedOption) return true;
const value = propsData.value;
const label = propsData.label || '';
const textContent = (elm && elm.textContent) || (children || []).reduce((str, node) => {
@ -545,6 +529,7 @@
this.focusIndex = -1;
this.unchangedQuery = true;
this.values = [];
this.filterQueryChange = false;
},
handleKeydown (e) {
if (e.key === 'Backspace'){
@ -644,11 +629,15 @@
if (!this.autoComplete) this.$nextTick(() => inputField.focus());
}
this.broadcast('Drop', 'on-update-popper');
setTimeout(() => {
this.filterQueryChange = false;
},300)
},
onQueryChange(query) {
if (query.length > 0 && query !== this.query) this.visible = true;
this.query = query;
this.unchangedQuery = this.visible;
this.filterQueryChange = true;
},
toggleHeaderFocus({type}){
if (this.disabled) {
@ -664,13 +653,6 @@
this.hasExpectedValue = true;
}
},
/**
* 下面的方法 filterable 输入内容时标记用于区分和直接选择而引起的 bug
* #4273
* */
handleFilterInputKeyDown () {
this.filterQueryKeyDown = true;
},
},
watch: {
value(value){