Commit c1a2d95fd4c28a51e7b4aafeed2dbc2e8ddb7251

Authored by Aresn
Committed by GitHub
2 parents 5d076fc5 20719945

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

Revert "Fix select"
src/components/select/functional-options.vue
... ... @@ -18,17 +18,11 @@
18 18 },
19 19 },
20 20 functional: true,
21   - render(h, {props, parent}) {
22   - // In order to response data changes,i do this hack. #4372
23   - if(props.slotOptions.length > 0) {
24   - for(let i in props.slotOptions) {
25   - if(props.slotOptions[i].key !== parent.$slots.default[i].key) {
26   - props.slotUpdateHook();
27   - break;
28   - }
29   - }
30   - }
31   - if(props.slotOptions && parent.$slots.default && props.slotOptions.length !== parent.$slots.default.length) props.slotUpdateHook();
  21 + render(h, {props, parent}){
  22 + // to detect changes in the $slot children/options we do this hack
  23 + // so we can trigger the parents computed properties and have everything reactive
  24 + // although $slot.default is not
  25 + if (props.slotOptions !== parent.$slots.default) props.slotUpdateHook();
32 26 return props.options;
33 27 }
34 28 };
... ...
src/components/select/select.vue
... ... @@ -356,12 +356,14 @@
356 356 });
357 357 });
358 358 }
  359 + let hasDefaultSelected = slotOptions.some(option => this.query === option.key);
359 360 for (let option of slotOptions) {
360 361  
361 362 const cOptions = option.componentOptions;
362 363 if (!cOptions) continue;
363 364 if (cOptions.tag.match(optionGroupRegexp)){
364 365 let children = cOptions.children;
  366 +
365 367 // remove filtered children
366 368 if (this.filterable){
367 369 children = children.filter(
... ... @@ -378,8 +380,11 @@
378 380 if (cOptions.children.length > 0) selectOptions.push({...option});
379 381 } else {
380 382 // ignore option if not passing filter
381   - const optionPassesFilter = this.filterable ? this.validateOption(cOptions) : option;
382   - if (!optionPassesFilter) continue;
  383 + if (!hasDefaultSelected) {
  384 + const optionPassesFilter = this.filterable ? this.validateOption(cOptions) : option;
  385 + if (!optionPassesFilter) continue;
  386 + }
  387 +
383 388 optionCounter = optionCounter + 1;
384 389 selectOptions.push(this.processOption(option, selectedValues, optionCounter === currentIndex));
385 390 }
... ... @@ -636,9 +641,6 @@
636 641 },
637 642 updateSlotOptions(){
638 643 this.slotOptions = this.$slots.default;
639   - // #4372 issue, i find that this.query's value affects the judgment of the validateOption method.
640   - this.query = '';
641   - this.focusIndex = -1;
642 644 },
643 645 checkUpdateStatus() {
644 646 if (this.getInitialValue().length > 0 && this.selectOptions.length === 0) {
... ...