Skip to content

Commit 83bc2a8

Browse files
fix(simple-combo): prevent group header selection on Enter key press - 17.2.x (#14432)
1 parent 6ba84e6 commit 83bc2a8

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ All notable changes for each version of this project will be documented in this
2929
- `IgxSimpleCombo`
3030
- **Behavioral Change** When bound to `ngModel` and `formControlName` directives, the model would not be updated when the user types into the input and will only be updated on selection.
3131
- **Behavioral Change** The `selectionChanging` event will now trigger when typing the first character in the input if there is a previously selected value in the `IgxSimpleCombo`.
32+
- **Behavioral Change** Updated behavior to maintain the entered text in the input field upon pressing Enter while the combo input is focused, ensuring uninterrupted focus for continuous filtering. Additionally, the dropdown menu now remains open to display filtered results.
3233

3334

3435
## 17.1.0

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export class IgxComboDropDownComponent extends IgxDropDownComponent implements I
128128
public override navigatePrev() {
129129
if (this._focusedItem && this._focusedItem.index === 0 && this.virtDir.state.startIndex === 0) {
130130
this.combo.focusSearchInput(false);
131+
this.focusedItem = null;
131132
} else {
132133
super.navigatePrev();
133134
}

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,36 @@ describe('IgxSimpleCombo', () => {
17341734
expect(combo.filteredData.length).toEqual(1);
17351735
expect(combo.filteredData[0].field).toEqual('Arizona');
17361736
}));
1737+
1738+
it('should not select the first item when combo is focused there is no focus item and Enter is pressed', fakeAsync(() => {
1739+
combo.open();
1740+
tick();
1741+
fixture.detectChanges();
1742+
1743+
UIInteractions.simulateTyping('ariz', input);
1744+
tick();
1745+
fixture.detectChanges();
1746+
1747+
expect(combo.dropdown.collapsed).toBe(false);
1748+
1749+
UIInteractions.triggerKeyDownEvtUponElem('ArrowDown', input.nativeElement);
1750+
tick();
1751+
fixture.detectChanges();
1752+
1753+
input.nativeElement.focus();
1754+
tick();
1755+
fixture.detectChanges();
1756+
1757+
combo.dropdown.focusedItem = undefined;
1758+
tick();
1759+
fixture.detectChanges();
1760+
1761+
UIInteractions.triggerKeyDownEvtUponElem('Enter', input.nativeElement);
1762+
tick();
1763+
fixture.detectChanges();
1764+
1765+
expect(combo.comboInput.value).toEqual('ariz');
1766+
}));
17371767
});
17381768

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

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,17 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
331331
return;
332332
}
333333
if (!this.dropdown.collapsed) {
334-
this.select(this.dropdown.focusedItem.itemID);
335-
event.preventDefault();
336-
event.stopPropagation();
337-
this.close();
334+
const focusedItem = this.dropdown.focusedItem;
335+
if (focusedItem && !focusedItem.isHeader) {
336+
this.select(focusedItem.itemID);
337+
event.preventDefault();
338+
event.stopPropagation();
339+
this.close();
340+
} else {
341+
event.preventDefault();
342+
event.stopPropagation();
343+
this.comboInput.focus();
344+
}
338345
}
339346
// manually trigger text selection as it will not be triggered during editing
340347
this.textSelection.trigger();

0 commit comments

Comments
 (0)