Skip to content

Commit 3334021

Browse files
fix(simple-combo): correct filtering functionality when combo is focused
1 parent ff03def commit 3334021

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

projects/igniteui-angular/src/lib/simple-combo/simple-combo.component.spec.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,20 +1530,25 @@ describe('IgxSimpleCombo', () => {
15301530
});
15311531

15321532
it('should properly filter dropdown when a key is pressed while the combo is focused but not opened', fakeAsync(() => {
1533-
spyOn(combo, 'open').and.callThrough();
1533+
expect(combo.collapsed).toEqual(true);
1534+
1535+
combo.handleInputChange('z');
1536+
tick();
1537+
fixture.detectChanges();
1538+
1539+
expect(combo.filteredData.length).toEqual(1);
15341540

1535-
const event = UIInteractions.getKeyboardEvent('keydown', 'z');
1541+
combo.close();
1542+
tick();
1543+
fixture.detectChanges();
15361544

15371545
expect(combo.collapsed).toEqual(true);
15381546

1539-
combo.handleKeyDown(event);
1547+
combo.handleInputChange(' ');
15401548
tick();
15411549
fixture.detectChanges();
15421550

1543-
expect(combo.collapsed).toEqual(false);
1544-
expect(combo.open).toHaveBeenCalled();
1545-
expect(combo.filteredData.length).toEqual(1);
1546-
expect(combo.filteredData).toEqual([{ field: 'Arizona', region: 'Mount' }]);
1551+
expect(combo.filteredData.length).toEqual(12);
15471552
}));
15481553
});
15491554

projects/igniteui-angular/src/lib/simple-combo/simple-combo.component.ts

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
240240
this.filterValue = this.searchValue = this.comboInput.value;
241241
return;
242242
}
243-
this.filterValue = this.searchValue = '';
243+
if (!this.comboInput.value) {
244+
this.filterValue = this.searchValue = '';
245+
}
244246
});
245247
this.dropdown.opened.pipe(takeUntil(this.destroy$)).subscribe(() => {
246248
if (this.composing) {
@@ -288,7 +290,7 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
288290
if (this.collapsed && this.comboInput.focused) {
289291
this.open();
290292
}
291-
if (!this.comboInput.value.trim() && super.selection.length) {
293+
if (!this.comboInput.value.trim() && super.selection.length && super.selection[0][this.valueKey] !== "") {
292294
// handle clearing of input by space
293295
this.clearSelection();
294296
this._onChangeCallback(null);
@@ -337,20 +339,6 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
337339
this.clearOnBlur();
338340
this.close();
339341
}
340-
if (this.collapsed && event.key && event.key.length > 0
341-
&& event.key !== this.platformUtil.KEYMAP.CONTROL && !event.altKey && !event.metaKey) {
342-
const newFilterValue = this.filterValue + event.key.toLowerCase();
343-
this.filterValue = newFilterValue;
344-
this.searchValue = newFilterValue;
345-
this.filteredData = this.data.filter(item => this.findAllMatches(item));
346-
this.open();
347-
}
348-
if (event.key === this.platformUtil.KEYMAP.SPACE && this.filteredData.length !== this.data.length) {
349-
this.clearSelection();
350-
this.filterValue = '';
351-
this.searchValue = '';
352-
this.filteredData = this.data;
353-
}
354342
this.composing = false;
355343
super.handleKeyDown(event);
356344
}

0 commit comments

Comments
 (0)