Trim label so we can compare and use label better

This commit is contained in:
Sergio Crisostomo 2018-05-11 10:52:58 +02:00
parent 52cfcd662b
commit 5266c9054b

View file

@ -266,7 +266,9 @@
}, },
queryStringMatchesSelectedOption(){ queryStringMatchesSelectedOption(){
const selectedOptions = this.values[0]; const selectedOptions = this.values[0];
return selectedOptions && !this.multiple && this.unchangedQuery && this.query === selectedOptions.label; if (!selectedOptions) return false;
const [query, label] = [this.query, selectedOptions.label].map(str => (str || '').trim());
return !this.multiple && this.unchangedQuery && query === label;
}, },
localeNotFoundText () { localeNotFoundText () {
if (typeof this.notFoundText === 'undefined') { if (typeof this.notFoundText === 'undefined') {
@ -438,7 +440,7 @@
const label = propsData.label || ''; const label = propsData.label || '';
const textContent = elm && elm.textContent || ''; const textContent = elm && elm.textContent || '';
const stringValues = JSON.stringify([value, label, textContent]); const stringValues = JSON.stringify([value, label, textContent]);
const query = this.query.toLowerCase(); const query = this.query.toLowerCase().trim();
return stringValues.toLowerCase().includes(query); return stringValues.toLowerCase().includes(query);
}, },
@ -564,7 +566,7 @@
this.isFocused = true; // so we put back focus after clicking with mouse on option elements this.isFocused = true; // so we put back focus after clicking with mouse on option elements
} else { } else {
this.query = option.label; this.query = String(option.label).trim();
this.values = [option]; this.values = [option];
this.lastRemoteQuery = ''; this.lastRemoteQuery = '';
this.hideMenu(); this.hideMenu();
@ -652,7 +654,7 @@
// restore query value in filterable single selects // restore query value in filterable single selects
const [selectedOption] = this.values; const [selectedOption] = this.values;
if (selectedOption && this.filterable && !this.multiple && !focused){ if (selectedOption && this.filterable && !this.multiple && !focused){
const selectedLabel = selectedOption.label || selectedOption.value; const selectedLabel = String(selectedOption.label || selectedOption.value).trim();
if (selectedLabel && this.query !== selectedLabel) { if (selectedLabel && this.query !== selectedLabel) {
this.preventRemoteCall = true; this.preventRemoteCall = true;
this.query = selectedLabel; this.query = selectedLabel;