Merge pull request #4550 from iview/revert-4403-fix-select

Revert "Fix select"
This commit is contained in:
Aresn 2018-09-18 16:20:37 +08:00 committed by GitHub
commit c1a2d95fd4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 16 deletions

View file

@ -19,16 +19,10 @@
}, },
functional: true, functional: true,
render(h, {props, parent}){ render(h, {props, parent}){
// In order to response data changes,i do this hack. #4372 // to detect changes in the $slot children/options we do this hack
if(props.slotOptions.length > 0) { // so we can trigger the parents computed properties and have everything reactive
for(let i in props.slotOptions) { // although $slot.default is not
if(props.slotOptions[i].key !== parent.$slots.default[i].key) { if (props.slotOptions !== parent.$slots.default) props.slotUpdateHook();
props.slotUpdateHook();
break;
}
}
}
if(props.slotOptions && parent.$slots.default && props.slotOptions.length !== parent.$slots.default.length) props.slotUpdateHook();
return props.options; return props.options;
} }
}; };

View file

@ -356,12 +356,14 @@
}); });
}); });
} }
let hasDefaultSelected = slotOptions.some(option => this.query === option.key);
for (let option of slotOptions) { for (let option of slotOptions) {
const cOptions = option.componentOptions; const cOptions = option.componentOptions;
if (!cOptions) continue; if (!cOptions) continue;
if (cOptions.tag.match(optionGroupRegexp)){ if (cOptions.tag.match(optionGroupRegexp)){
let children = cOptions.children; let children = cOptions.children;
// remove filtered children // remove filtered children
if (this.filterable){ if (this.filterable){
children = children.filter( children = children.filter(
@ -378,8 +380,11 @@
if (cOptions.children.length > 0) selectOptions.push({...option}); if (cOptions.children.length > 0) selectOptions.push({...option});
} else { } else {
// ignore option if not passing filter // ignore option if not passing filter
if (!hasDefaultSelected) {
const optionPassesFilter = this.filterable ? this.validateOption(cOptions) : option; const optionPassesFilter = this.filterable ? this.validateOption(cOptions) : option;
if (!optionPassesFilter) continue; if (!optionPassesFilter) continue;
}
optionCounter = optionCounter + 1; optionCounter = optionCounter + 1;
selectOptions.push(this.processOption(option, selectedValues, optionCounter === currentIndex)); selectOptions.push(this.processOption(option, selectedValues, optionCounter === currentIndex));
} }
@ -636,9 +641,6 @@
}, },
updateSlotOptions(){ updateSlotOptions(){
this.slotOptions = this.$slots.default; this.slotOptions = this.$slots.default;
// #4372 issue, i find that this.query's value affects the judgment of the validateOption method.
this.query = '';
this.focusIndex = -1;
}, },
checkUpdateStatus() { checkUpdateStatus() {
if (this.getInitialValue().length > 0 && this.selectOptions.length === 0) { if (this.getInitialValue().length > 0 && this.selectOptions.length === 0) {