Skip to content

Commit

Permalink
fix(datepicker): prevent focustrap to resotre focus on destroy
Browse files Browse the repository at this point in the history
fixes #2372

Closes #2392
  • Loading branch information
Benoit Charbonnier authored and pkozlowski-opensource committed May 23, 2018
1 parent 39d458d commit dcd7111
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/util/focus-trap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('ngbFocusTrap', () => {
});
});

it('should save/restore focused element when autofocus is set', () => {
it('should focus element decorated with ngbAutofocus when created', () => {
TestBed.configureTestingModule({
declarations: [TestComponent, FocusTrapComponent],
providers: [NgbFocusTrapFactory, {provide: Autofocus, useValue: true}]
Expand All @@ -71,7 +71,7 @@ describe('ngbFocusTrap', () => {
// let's destroy the focustrap (removing <focus-trapped>)
instance.show = false;
fixture.detectChanges();
expect(document.activeElement).toBe(initial);
expect(document.activeElement).not.toBe(button);
});
});

Expand Down
5 changes: 0 additions & 5 deletions src/util/focus-trap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ enum DIRECTION {
export class NgbFocusTrap {
private _removeDocumentListener;
private _direction: DIRECTION = DIRECTION.FORWARD;
private _previouslyFocused: HTMLElement | null = null;
private _endOfDocument: HTMLElement | null = null;

/**
Expand Down Expand Up @@ -65,7 +64,6 @@ export class NgbFocusTrap {
});

if (autofocus === true) {
this._previouslyFocused = document.activeElement as HTMLElement;
this._focusInitial();
}
}
Expand Down Expand Up @@ -109,9 +107,6 @@ export class NgbFocusTrap {
destroy() {
this._removeDocumentListener();
this._document.body.removeChild(this._endOfDocument);
if (this._previouslyFocused) {
this._previouslyFocused.focus();
}
}
}

Expand Down

0 comments on commit dcd7111

Please sign in to comment.