Skip to content

Commit d2994dd

Browse files
Merge pull request #14209 from IgniteUI/ganastasov/fix-14187-17.2.x
fix(simple-combo): filter on typing when combo is focused but not opened - 17.2.x
2 parents 257e9c1 + f31498b commit d2994dd

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,6 +1686,52 @@ describe('IgxSimpleCombo', () => {
16861686

16871687
expect(comboInput.nativeElement.value).toEqual('Connecticut');
16881688
});
1689+
1690+
it('should properly filter dropdown when a key is pressed while the combo is focused but not opened, with no selected item', fakeAsync(() => {
1691+
expect(combo.collapsed).toEqual(true);
1692+
1693+
// filter with a specific character when there is no selected item
1694+
combo.handleInputChange('z');
1695+
tick();
1696+
fixture.detectChanges();
1697+
1698+
expect(combo.filteredData.length).toEqual(1);
1699+
expect(combo.filteredData[0].field).toEqual('Arizona');
1700+
1701+
combo.close();
1702+
tick();
1703+
fixture.detectChanges();
1704+
1705+
expect(combo.collapsed).toEqual(true);
1706+
1707+
// filter with ' ' when there is no selected item
1708+
combo.handleInputChange(' ');
1709+
tick();
1710+
fixture.detectChanges();
1711+
1712+
expect(combo.filteredData.length).toEqual(12);
1713+
}));
1714+
1715+
it('should properly filter dropdown when a key is pressed while the combo is focused but not opened, with a selected item', fakeAsync(() => {
1716+
// select an item
1717+
combo.select('Connecticut');
1718+
tick();
1719+
fixture.detectChanges();
1720+
1721+
expect(combo.selection.field).toEqual('Connecticut');
1722+
1723+
combo.close();
1724+
tick();
1725+
fixture.detectChanges();
1726+
1727+
// filter with a specific character when there is a selected item
1728+
combo.handleInputChange('z');
1729+
tick();
1730+
fixture.detectChanges();
1731+
1732+
expect(combo.filteredData.length).toEqual(1);
1733+
expect(combo.filteredData[0].field).toEqual('Arizona');
1734+
}));
16891735
});
16901736

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

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
240240
this.filterValue = this.searchValue = this.comboInput.value;
241241
return;
242242
}
243-
this.filterValue = this.searchValue = '';
244243
});
245244
this.dropdown.opened.pipe(takeUntil(this.destroy$)).subscribe(() => {
246245
if (this.composing) {
@@ -281,12 +280,12 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
281280

282281
/** @hidden @internal */
283282
public override handleInputChange(event?: any): void {
284-
if (event !== undefined) {
285-
this.filterValue = this.searchValue = typeof event === 'string' ? event : event.target.value;
286-
}
287283
if (this.collapsed && this.comboInput.focused) {
288284
this.open();
289285
}
286+
if (event !== undefined) {
287+
this.filterValue = this.searchValue = typeof event === 'string' ? event : event.target.value;
288+
}
290289
if (!this.comboInput.value.trim() && super.selection.length) {
291290
// handle clearing of input by space
292291
this.clearSelection();

0 commit comments

Comments
 (0)