Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2080,6 +2080,29 @@ describe('IgxSimpleCombo', () => {
fixture.detectChanges();
expect(document.activeElement).toEqual(thirdComboInput.nativeElement);
}));

it('should lose focus when clicking outside the combo', fakeAsync(() => {
// Initially combo is not focused
expect(document.activeElement).not.toBe(input.nativeElement);

// Click inside combo input to focus it
input.triggerEventHandler('focus', {});
input.triggerEventHandler('click', UIInteractions.getMouseEvent('click'));
fixture.detectChanges();

// Verify combo is focused and opened
expect(document.activeElement).toBe(input.nativeElement);
expect(combo.collapsed).toBe(false);

// Simulate outside click by clicking on document body
// This triggers the blur event which is what happens on outside clicks
input.triggerEventHandler('blur', {});
document.body.click();
tick();
fixture.detectChanges();

expect(document.activeElement).not.toBe(input.nativeElement);
}));
});

describe('Form control tests: ', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,13 @@ export class IgxSimpleComboComponent extends IgxComboBaseDirective implements Co
}
if (this.getEditElement() && !args.event) {
this._collapsing = true;
// Only focus back when programmatically closing (no user event)
// to avoid focus loops when user clicks on another combo
this.comboInput.focus();
} else {
this.clearOnBlur();
this._onTouchedCallback();
}
this.comboInput.focus();
});

// in reactive form the control is not present initially
Expand Down
Loading