Skip to content

Commit da0d509

Browse files
fix(simple-combo): filter on typing when combo is focused but not opened
1 parent 2cbc95a commit da0d509

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,6 +1528,23 @@ describe('IgxSimpleCombo', () => {
15281528
expect(combo.filteredData.length).toBeLessThan(combo.data.length)
15291529
expect(combo.filteredData[0].field).toBe(target.value)
15301530
});
1531+
1532+
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();
1534+
1535+
const event = UIInteractions.getKeyboardEvent('keydown', 'z');
1536+
1537+
expect(combo.collapsed).toEqual(true);
1538+
1539+
combo.handleKeyDown(event);
1540+
tick();
1541+
fixture.detectChanges();
1542+
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' }]);
1547+
}));
15311548
});
15321549

15331550
describe('Display density', () => {

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,23 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
327327
// manually trigger text selection as it will not be triggered during editing
328328
this.textSelection.trigger();
329329
return;
330-
}
331-
if (event.key === this.platformUtil.KEYMAP.BACKSPACE
330+
} else if (event.key === this.platformUtil.KEYMAP.BACKSPACE
332331
|| event.key === this.platformUtil.KEYMAP.DELETE) {
333332
this._updateInput = false;
334333
this.clearSelection(true);
335-
}
336-
if (!this.collapsed && event.key === this.platformUtil.KEYMAP.TAB) {
334+
} else if (event.key === this.platformUtil.KEYMAP.TAB) {
337335
this.clearOnBlur();
338336
this.close();
337+
} else {
338+
if (event.key !== this.platformUtil.KEYMAP.ARROW_DOWN && event.key !== this.platformUtil.KEYMAP.SPACE) {
339+
const newFilterValue = this.filterValue + event.key.toLowerCase();
340+
this.filterValue = newFilterValue;
341+
this.searchValue = newFilterValue;
342+
this.filteredData = this.data.filter(item => this.findAllMatches(item));
343+
if (this.filteredData.length > 0 && this.collapsed) {
344+
this.open();
345+
}
346+
}
339347
}
340348
this.composing = false;
341349
super.handleKeyDown(event);

0 commit comments

Comments
 (0)