Commit d4f39edc359c515dbf62b509a89b2070ffaf79c7
Committed by
GitHub

Merge pull request #3576 from SergioCrisostomo/refactor-select
Select related fixes
Showing
2 changed files
with
18 additions
and
16 deletions
Show diff stats
src/components/select/select.vue
@@ -56,12 +56,12 @@ | @@ -56,12 +56,12 @@ | ||
56 | > | 56 | > |
57 | <ul v-show="showNotFoundLabel" :class="[prefixCls + '-not-found']"><li>{{ localeNotFoundText }}</li></ul> | 57 | <ul v-show="showNotFoundLabel" :class="[prefixCls + '-not-found']"><li>{{ localeNotFoundText }}</li></ul> |
58 | <ul :class="prefixCls + '-dropdown-list'"> | 58 | <ul :class="prefixCls + '-dropdown-list'"> |
59 | - <functional-options | ||
60 | - v-if="(!remote) || (remote && !loading)" | ||
61 | - :options="selectOptions" | ||
62 | - :slot-update-hook="updateSlotOptions" | ||
63 | - :slot-options="slotOptions" | ||
64 | - ></functional-options> | 59 | + <functional-options |
60 | + v-if="(!remote) || (remote && !loading)" | ||
61 | + :options="selectOptions" | ||
62 | + :slot-update-hook="updateSlotOptions" | ||
63 | + :slot-options="slotOptions" | ||
64 | + ></functional-options> | ||
65 | </ul> | 65 | </ul> |
66 | <ul v-show="loading" :class="[prefixCls + '-loading']">{{ localeLoadingText }}</ul> | 66 | <ul v-show="loading" :class="[prefixCls + '-loading']">{{ localeLoadingText }}</ul> |
67 | </Drop> | 67 | </Drop> |
@@ -207,7 +207,7 @@ | @@ -207,7 +207,7 @@ | ||
207 | 207 | ||
208 | // set the initial values if there are any | 208 | // set the initial values if there are any |
209 | if (this.values.length > 0 && !this.remote && this.selectOptions.length > 0){ | 209 | if (this.values.length > 0 && !this.remote && this.selectOptions.length > 0){ |
210 | - this.values = this.values.map(this.getOptionData); | 210 | + this.values = this.values.map(this.getOptionData).filter(Boolean); |
211 | } | 211 | } |
212 | 212 | ||
213 | if (this.values.length > 0 && this.selectOptions.length === 0){ | 213 | if (this.values.length > 0 && this.selectOptions.length === 0){ |
@@ -307,7 +307,7 @@ | @@ -307,7 +307,7 @@ | ||
307 | const slotOptions = (this.slotOptions || []); | 307 | const slotOptions = (this.slotOptions || []); |
308 | let optionCounter = -1; | 308 | let optionCounter = -1; |
309 | const currentIndex = this.focusIndex; | 309 | const currentIndex = this.focusIndex; |
310 | - const selectedValues = this.values.map(({value}) => value); | 310 | + const selectedValues = this.values.filter(Boolean).map(({value}) => value); |
311 | if (this.autoComplete) { | 311 | if (this.autoComplete) { |
312 | const copyChildren = (node, fn) => { | 312 | const copyChildren = (node, fn) => { |
313 | return { | 313 | return { |
@@ -398,7 +398,7 @@ | @@ -398,7 +398,7 @@ | ||
398 | const {multiple, value} = this; | 398 | const {multiple, value} = this; |
399 | let initialValue = Array.isArray(value) ? value : [value]; | 399 | let initialValue = Array.isArray(value) ? value : [value]; |
400 | if (!multiple && (typeof initialValue[0] === 'undefined' || String(initialValue[0]).trim() === '')) initialValue = []; | 400 | if (!multiple && (typeof initialValue[0] === 'undefined' || String(initialValue[0]).trim() === '')) initialValue = []; |
401 | - return initialValue; | 401 | + return initialValue.filter(Boolean); |
402 | }, | 402 | }, |
403 | processOption(option, values, isFocused){ | 403 | processOption(option, values, isFocused){ |
404 | if (!option.componentOptions) return option; | 404 | if (!option.componentOptions) return option; |
@@ -482,6 +482,7 @@ | @@ -482,6 +482,7 @@ | ||
482 | 482 | ||
483 | // Esc slide-up | 483 | // Esc slide-up |
484 | if (e.key === 'Escape') { | 484 | if (e.key === 'Escape') { |
485 | + e.stopPropagation(); | ||
485 | this.hideMenu(); | 486 | this.hideMenu(); |
486 | } | 487 | } |
487 | // next | 488 | // next |
@@ -493,7 +494,8 @@ | @@ -493,7 +494,8 @@ | ||
493 | this.navigateOptions(1); | 494 | this.navigateOptions(1); |
494 | } | 495 | } |
495 | // enter | 496 | // enter |
496 | - if (e.key === 'Enter' && this.focusIndex > -1) { | 497 | + if (e.key === 'Enter') { |
498 | + if (this.focusIndex === -1) return this.hideMenu(); | ||
497 | const optionComponent = this.flatOptions[this.focusIndex]; | 499 | const optionComponent = this.flatOptions[this.focusIndex]; |
498 | const option = this.getOptionData(optionComponent.componentOptions.propsData.value); | 500 | const option = this.getOptionData(optionComponent.componentOptions.propsData.value); |
499 | this.onOptionClick(option); | 501 | this.onOptionClick(option); |
@@ -580,7 +582,7 @@ | @@ -580,7 +582,7 @@ | ||
580 | 582 | ||
581 | if (value === '') this.values = []; | 583 | if (value === '') this.values = []; |
582 | else if (JSON.stringify(value) !== JSON.stringify(publicValue)) { | 584 | else if (JSON.stringify(value) !== JSON.stringify(publicValue)) { |
583 | - this.$nextTick(() => this.values = getInitialValue().map(getOptionData)); | 585 | + this.$nextTick(() => this.values = getInitialValue().map(getOptionData).filter(Boolean)); |
584 | } | 586 | } |
585 | }, | 587 | }, |
586 | values(now, before){ | 588 | values(now, before){ |
@@ -592,8 +594,8 @@ | @@ -592,8 +594,8 @@ | ||
592 | // v-model is always just the value, event with labelInValue === true | 594 | // v-model is always just the value, event with labelInValue === true |
593 | const vModelValue = this.labelInValue ? | 595 | const vModelValue = this.labelInValue ? |
594 | (this.multiple ? this.publicValue.map(({value}) => value) | 596 | (this.multiple ? this.publicValue.map(({value}) => value) |
595 | - : | ||
596 | - this.publicValue.value) : this.publicValue; | 597 | + : |
598 | + this.publicValue.value) : this.publicValue; | ||
597 | this.$emit('input', vModelValue); // to update v-model | 599 | this.$emit('input', vModelValue); // to update v-model |
598 | this.$emit('on-change', this.publicValue); | 600 | this.$emit('on-change', this.publicValue); |
599 | this.dispatch('FormItem', 'on-form-change', this.publicValue); | 601 | this.dispatch('FormItem', 'on-form-change', this.publicValue); |
@@ -659,7 +661,7 @@ | @@ -659,7 +661,7 @@ | ||
659 | }, | 661 | }, |
660 | selectOptions(){ | 662 | selectOptions(){ |
661 | if (this.hasExpectedValue){ | 663 | if (this.hasExpectedValue){ |
662 | - this.values = this.values.map(this.getOptionData); | 664 | + this.values = this.values.map(this.getOptionData).filter(Boolean); |
663 | this.hasExpectedValue = false; | 665 | this.hasExpectedValue = false; |
664 | } | 666 | } |
665 | 667 |
src/locale/lang/sv-SE.js
@@ -6,7 +6,7 @@ const lang = { | @@ -6,7 +6,7 @@ const lang = { | ||
6 | select: { | 6 | select: { |
7 | placeholder: 'Välj', | 7 | placeholder: 'Välj', |
8 | noMatch: 'Ingen träff', | 8 | noMatch: 'Ingen träff', |
9 | - loading: 'Ladar' | 9 | + loading: 'Laddar' |
10 | }, | 10 | }, |
11 | table: { | 11 | table: { |
12 | noDataText: 'Ingen data', | 12 | noDataText: 'Ingen data', |
@@ -102,4 +102,4 @@ const lang = { | @@ -102,4 +102,4 @@ const lang = { | ||
102 | 102 | ||
103 | setLang(lang); | 103 | setLang(lang); |
104 | 104 | ||
105 | -export default lang; | ||
106 | \ No newline at end of file | 105 | \ No newline at end of file |
106 | +export default lang; |