Skip to content

Commit

Permalink
fix: Make server-side filtering case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
tulioag committed May 10, 2021
1 parent f88fa4c commit b1500a4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/vaadin-combo-box-mixin.html
Expand Up @@ -687,8 +687,9 @@
this.value = '';
}
} else {
const toLowerCase = (item) => item && item.toLowerCase && item.toLowerCase();
const itemsMatchedByLabel = this.filteredItems
&& this.filteredItems.filter(item => this._getItemLabel(item) === this._inputElementValue)
&& this.filteredItems.filter(item => toLowerCase(this._getItemLabel(item)) === toLowerCase(this._inputElementValue))
|| [];
if (this.allowCustomValue
// to prevent a repetitive input value being saved after pressing ESC and Tab.
Expand All @@ -701,7 +702,7 @@
this._selectItemForValue(customValue);
this.value = customValue;
}
} else if (!this.allowCustomValue && !this.opened && itemsMatchedByLabel.length == 1) {
} else if (!this.allowCustomValue && !this.opened && itemsMatchedByLabel.length > 0) {
this.value = this._getItemValue(itemsMatchedByLabel[0]);
} else {
this._inputElementValue = this.selectedItem ? this._getItemLabel(this.selectedItem) : (this.value || '');
Expand Down
32 changes: 32 additions & 0 deletions test/lazy-loading.html
Expand Up @@ -925,6 +925,38 @@
expect(comboBox.value).to.equal('item 12');
});

it('should set value without auto-open-disabled even if case does not match', () => {
comboBox.autoOpenDisabled = false;
expect(comboBox.autoOpenDisabled).to.be.false;

comboBox._inputElementValue = 'ItEm 12';
comboBox.filter = 'item 12';
expect(comboBox.opened).to.be.false;
expect(comboBox.hasAttribute('focused')).to.be.false;
expect(comboBox.value).to.equal('item 12');
});

it('should set value with auto-open-disabled even if case does not match', () => {
comboBox.autoOpenDisabled = true;
expect(comboBox.autoOpenDisabled).to.be.true;

comboBox._inputElementValue = 'iTem 12';
comboBox.filter = 'item 12';
expect(comboBox.opened).to.be.false;
expect(comboBox.hasAttribute('focused')).to.be.false;
expect(comboBox.value).to.equal('item 12');
});

it('should set value with multiple matches that differ only in case', () => {
returnedItems = ['item 12', 'IteM 12'];

comboBox._inputElementValue = 'IteM 12';
comboBox.filter = 'IteM 12';
expect(comboBox.opened).to.be.false;
expect(comboBox.hasAttribute('focused')).to.be.false;
expect(comboBox.value).to.equal('item 12');
});

it('should keep empty value if it is not an exact match', () => {
comboBox._inputElementValue = 'item';
comboBox.filter = 'item';
Expand Down

0 comments on commit b1500a4

Please sign in to comment.