Skip to content

Commit

Permalink
fix: (Core) Add setTimeout for IE11 on InitialFocusDirective (#4623)
Browse files Browse the repository at this point in the history
  • Loading branch information
JKMarkowski committed Feb 11, 2021
1 parent 5c766fd commit d7aecee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { InitialFocusDirective } from './initial-focus.directive';
import { Component, ElementRef, ViewChild } from '@angular/core';
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';

@Component({
template: `
Expand Down Expand Up @@ -33,14 +33,16 @@ describe('InitialFocusDirective', () => {
component = fixture.componentInstance;
});

it('should focus element', () => {
it('should focus element', fakeAsync(() => {
fixture.detectChanges();
tick(10);
expect(document.activeElement).toBe(component.elementToFocus.nativeElement);
});
}));

it('should focus nested element', () => {
it('should focus nested element', fakeAsync(() => {
component.rootElementTabIndex = -1;
fixture.detectChanges();
tick(10);
expect(document.activeElement).toBe(component.nestedElementToFocus.nativeElement);
});
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class InitialFocusDirective implements AfterViewInit {
/** @hidden */
ngAfterViewInit(): void {
if (this.enabled) {
this._focusFirstTabbableElement();
setTimeout(() => this._focusFirstTabbableElement())
}
}

Expand Down

0 comments on commit d7aecee

Please sign in to comment.