Skip to content

Commit 21691cb

Browse files
feat(simple-combo): prevent non-existent item selection on Tab key
1 parent ab5c335 commit 21691cb

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

+18
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,24 @@ describe('IgxSimpleCombo', () => {
14421442
expect(combo.comboInput.value).toEqual('Connecticut');
14431443
});
14441444

1445+
it('should not select any item if input does not match data on tab key pressed', () => {
1446+
input.triggerEventHandler('focus', {});
1447+
fixture.detectChanges();
1448+
1449+
const toggleButton = fixture.debugElement.query(By.css('.' + CSS_CLASS_TOGGLEBUTTON));
1450+
toggleButton.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
1451+
fixture.detectChanges();
1452+
1453+
UIInteractions.simulateTyping('nonexistent', input);
1454+
fixture.detectChanges();
1455+
1456+
UIInteractions.triggerEventHandlerKeyDown('Tab', input);
1457+
fixture.detectChanges();
1458+
1459+
expect(combo.displayValue).toEqual('');
1460+
expect(combo.comboInput.value).toEqual('');
1461+
});
1462+
14451463
it('should not clear the input on blur with a partial match but it should select the match item', () => {
14461464
spyOn(combo.dropdown.closing, 'emit').and.callThrough();
14471465

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

+6
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,12 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
361361
this.clearSelection(true);
362362
}
363363
if (!this.collapsed && event.key === this.platformUtil.KEYMAP.TAB) {
364+
const filtered = this.filteredData.find(this.findAllMatches);
365+
if (filtered === null || filtered === undefined) {
366+
this.clearOnBlur();
367+
this.close();
368+
return;
369+
}
364370
const focusedItem = this.dropdown.focusedItem;
365371
if (focusedItem && !focusedItem.isHeader) {
366372
this.select(focusedItem.itemID);

0 commit comments

Comments
 (0)