Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
[NG] fix memory leak in focus trap (#2812)
Browse files Browse the repository at this point in the history
* [NG] fix memory leak in focus trap

Signed-off-by: stsogoo <[email protected]>
  • Loading branch information
Shijir committed Nov 7, 2018
1 parent e88b1e4 commit 98fc481
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/clr-angular/utils/focus-trap/focus-trap.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export class FocusTrapDirective implements AfterViewInit, OnDestroy {
}

private createFocusableOffScreenEl(): any {
const offScreenSpan = this.renderer.createElement('span');
// Not using Renderer2's createElement method because that leads to DOM leakage.
// https://github.com/angular/angular/issues/26954
const offScreenSpan = this.document.createElement('span');
this.renderer.setAttribute(offScreenSpan, 'tabindex', '0');
this.renderer.addClass(offScreenSpan, 'offscreen-focus-rebounder');

Expand Down Expand Up @@ -81,6 +83,11 @@ export class FocusTrapDirective implements AfterViewInit, OnDestroy {
) {
this.renderer.removeChild(this.document.body, this.topReboundEl);
this.renderer.removeChild(this.document.body, this.bottomReboundEl);

// These are here to to make sure that
// we completely delete all traces of the removed DOM objects.
delete this.topReboundEl;
delete this.bottomReboundEl;
}
}

Expand Down

0 comments on commit 98fc481

Please sign in to comment.