From a2576ff215df93ba4c389334fbe8cdefa648e4c8 Mon Sep 17 00:00:00 2001 From: RivaIvanova Date: Fri, 12 Dec 2025 17:23:05 +0200 Subject: [PATCH] fix(autocomplete): do not call super.handleKeyDown on Tab --- .../autocomplete/autocomplete.directive.spec.ts | 17 +++++++++++++++++ .../autocomplete/autocomplete.directive.ts | 1 + 2 files changed, 18 insertions(+) diff --git a/projects/igniteui-angular/src/lib/directives/autocomplete/autocomplete.directive.spec.ts b/projects/igniteui-angular/src/lib/directives/autocomplete/autocomplete.directive.spec.ts index 882f7c6ac61..60512495ab2 100644 --- a/projects/igniteui-angular/src/lib/directives/autocomplete/autocomplete.directive.spec.ts +++ b/projects/igniteui-angular/src/lib/directives/autocomplete/autocomplete.directive.spec.ts @@ -74,6 +74,23 @@ describe('IgxAutocomplete', () => { fixture.detectChanges(); expect(dropDown.collapsed).toBeTruthy(); })); + it('Should close dropdown on Tab without calling super.handleKeyDown', fakeAsync(() => { + spyOn(autocomplete, 'handleKeyDown').and.callThrough(); + spyOn(IgxDropDownItemNavigationDirective.prototype, 'handleKeyDown').and.callThrough(); + + input.nativeElement.focus(); + UIInteractions.setInputElementValue(input, 's', fixture); + tick(); + expect(dropDown.collapsed).toBeFalsy(); + + // IgxDropDownItemNavigationDirective handleKeyDown is not called when dropdown is closed on Tab + UIInteractions.triggerKeyDownEvtUponElem('Tab', input.nativeElement, true); + fixture.detectChanges(); + tick(); + expect(dropDown.collapsed).toBeTruthy(); + expect(autocomplete.handleKeyDown).toHaveBeenCalledTimes(1); + expect(IgxDropDownItemNavigationDirective.prototype.handleKeyDown).toHaveBeenCalledTimes(0); + })); it('Should open drop down on (Alt+)ArrowUp/ArrowDown', fakeAsync(() => { UIInteractions.triggerKeyDownEvtUponElem('ArrowDown', input.nativeElement, true); tick(); diff --git a/projects/igniteui-angular/src/lib/directives/autocomplete/autocomplete.directive.ts b/projects/igniteui-angular/src/lib/directives/autocomplete/autocomplete.directive.ts index fbc0dd8d6fe..7a7c499490e 100644 --- a/projects/igniteui-angular/src/lib/directives/autocomplete/autocomplete.directive.ts +++ b/projects/igniteui-angular/src/lib/directives/autocomplete/autocomplete.directive.ts @@ -273,6 +273,7 @@ export class IgxAutocompleteDirective extends IgxDropDownItemNavigationDirective case ' ': case 'home': case 'end': + case 'tab': return; default: super.handleKeyDown(event);