Commit 31788df30b739d279c9b994fad97ecf52f68b5dd
1 parent
7dbde804
Normalise behaviour when opening select with selected option present in options
Showing
1 changed file
with
12 additions
and
0 deletions
Show diff stats
src/components/select/select.vue
... | ... | @@ -122,6 +122,8 @@ |
122 | 122 | }; |
123 | 123 | }; |
124 | 124 | |
125 | + const ANIMATION_TIMEOUT = 300; | |
126 | + | |
125 | 127 | export default { |
126 | 128 | name: 'iSelect', |
127 | 129 | mixins: [ Emitter, Locale ], |
... | ... | @@ -230,6 +232,7 @@ |
230 | 232 | slotOptions: this.$slots.default, |
231 | 233 | caretPosition: -1, |
232 | 234 | lastRemoteQuery: '', |
235 | + unchangedQuery: true, | |
233 | 236 | hasExpectedValue: false, |
234 | 237 | preventRemoteCall: false, |
235 | 238 | }; |
... | ... | @@ -261,6 +264,10 @@ |
261 | 264 | [`${prefixCls}-selection-focused`]: this.isFocused |
262 | 265 | }; |
263 | 266 | }, |
267 | + queryStringMatchesSelectedOption(){ | |
268 | + const selectedOptions = this.values[0]; | |
269 | + return selectedOptions && !this.multiple && this.unchangedQuery && this.query === selectedOptions.value; | |
270 | + }, | |
264 | 271 | localeNotFoundText () { |
265 | 272 | if (typeof this.notFoundText === 'undefined') { |
266 | 273 | return this.t('i.select.noMatch'); |
... | ... | @@ -425,6 +432,7 @@ |
425 | 432 | }, |
426 | 433 | |
427 | 434 | validateOption({elm, propsData}){ |
435 | + if (this.queryStringMatchesSelectedOption) return true; | |
428 | 436 | const value = propsData.value; |
429 | 437 | const label = propsData.label || ''; |
430 | 438 | const textContent = elm && elm.textContent || ''; |
... | ... | @@ -446,6 +454,7 @@ |
446 | 454 | }, |
447 | 455 | hideMenu () { |
448 | 456 | this.toggleMenu(null, false); |
457 | + setTimeout(() => this.unchangedQuery = true, ANIMATION_TIMEOUT); | |
449 | 458 | }, |
450 | 459 | onClickOutside(event){ |
451 | 460 | if (this.visible) { |
... | ... | @@ -469,6 +478,7 @@ |
469 | 478 | } |
470 | 479 | }, |
471 | 480 | reset(){ |
481 | + this.unchangedQuery = true; | |
472 | 482 | this.values = []; |
473 | 483 | }, |
474 | 484 | handleKeydown (e) { |
... | ... | @@ -553,6 +563,7 @@ |
553 | 563 | |
554 | 564 | this.isFocused = true; // so we put back focus after clicking with mouse on option elements |
555 | 565 | } else { |
566 | + this.query = option.value; | |
556 | 567 | this.values = [option]; |
557 | 568 | this.lastRemoteQuery = ''; |
558 | 569 | this.hideMenu(); |
... | ... | @@ -565,6 +576,7 @@ |
565 | 576 | this.broadcast('Drop', 'on-update-popper'); |
566 | 577 | }, |
567 | 578 | onQueryChange(query) { |
579 | + this.unchangedQuery = false; | |
568 | 580 | this.query = query; |
569 | 581 | if (this.query.length > 0) this.visible = true; |
570 | 582 | }, | ... | ... |