Skip to content

Commit 3afb1e5

Browse files
Merge pull request #14345 from IgniteUI/ganastasov/fix-14187-18.0.x
fix(simple-combo): filter on typing when combo is focused but not opened - 18.0.x
2 parents ddbabc8 + 440ea78 commit 3afb1e5

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
@@ -239,7 +239,6 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
239239
this.filterValue = this.searchValue = this.comboInput.value;
240240
return;
241241
}
242-
this.filterValue = this.searchValue = '';
243242
});
244243
this.dropdown.opened.pipe(takeUntil(this.destroy$)).subscribe(() => {
245244
if (this.composing) {
@@ -279,12 +278,12 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
279278

280279
/** @hidden @internal */
281280
public override handleInputChange(event?: any): void {
282-
if (event !== undefined) {
283-
this.filterValue = this.searchValue = typeof event === 'string' ? event : event.target.value;
284-
}
285281
if (this.collapsed && this.comboInput.focused) {
286282
this.open();
287283
}
284+
if (event !== undefined) {
285+
this.filterValue = this.searchValue = typeof event === 'string' ? event : event.target.value;
286+
}
288287
if (!this.comboInput.value.trim() && super.selection.length) {
289288
// handle clearing of input by space
290289
this.clearSelection();

0 commit comments

Comments
 (0)