Commit 31788df30b739d279c9b994fad97ecf52f68b5dd

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