From e73275329036dc772f261e52b0aa1511bfdfa17d Mon Sep 17 00:00:00 2001 From: vincentfintend Date: Fri, 28 Sep 2018 18:23:28 +0800 Subject: [PATCH] fix select --- src/components/select/select.vue | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/components/select/select.vue b/src/components/select/select.vue index 15e2892..9687264 100644 --- a/src/components/select/select.vue +++ b/src/components/select/select.vue @@ -44,8 +44,6 @@ @on-input-focus="isFocused = true" @on-input-blur="isFocused = false" @on-clear="clearSingleSelect" - - @on-keydown="handleFilterInputKeyDown" /> @@ -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; + },500) }, 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){ -- libgit2 0.21.4