Skip to content

Commit 42430c0

Browse files
authored
fix(simple-combo): Focus on programmatically closing combo (#16867)
1 parent beceb6f commit 42430c0

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,6 +2208,29 @@ describe('IgxSimpleCombo', () => {
22082208
fixture.detectChanges();
22092209
expect(document.activeElement).toEqual(thirdComboInput.nativeElement);
22102210
}));
2211+
2212+
it('should lose focus when user closes combo by clicking outside', fakeAsync(() => {
2213+
// Initially combo is not focused
2214+
expect(document.activeElement).not.toBe(input.nativeElement);
2215+
2216+
// Click inside combo input to focus it
2217+
input.triggerEventHandler('focus', {});
2218+
input.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
2219+
fixture.detectChanges();
2220+
2221+
// Verify combo is focused and opened
2222+
expect(document.activeElement).toBe(input.nativeElement);
2223+
expect(combo.collapsed).toBe(false);
2224+
2225+
// Simulate outside click by clicking on document body
2226+
// This triggers the blur event which is what happens on outside clicks
2227+
input.triggerEventHandler('blur', {});
2228+
document.body.click();
2229+
tick();
2230+
fixture.detectChanges();
2231+
2232+
expect(document.activeElement).not.toBe(input.nativeElement);
2233+
}));
22112234
});
22122235

22132236
describe('Form control tests: ', () => {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,13 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
260260
}
261261
if (this.getEditElement() && !args.event) {
262262
this._collapsing = true;
263+
// Only focus back when programmatically closing (no user event)
264+
// to avoid focus loops when user clicks on another combo
265+
this.comboInput.focus();
263266
} else {
264267
this.clearOnBlur();
265268
this._onTouchedCallback();
266269
}
267-
this.comboInput.focus();
268270
});
269271

270272
// in reactive form the control is not present initially

0 commit comments

Comments
 (0)