Skip to content

Commit

Permalink
fix(modal): disconnect the resize observer once the modal body is rem…
Browse files Browse the repository at this point in the history
…oved
  • Loading branch information
arturovt authored and coryrylan committed Mar 21, 2022
1 parent 06c328a commit b95729e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion projects/angular/src/modal/modal-body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ import { Directive, ElementRef, NgZone, OnDestroy, Renderer2 } from '@angular/co
export class ClrModalBody implements OnDestroy {
private tabindex = '0';
private unlisteners: VoidFunction[] = [];
private observer: ResizeObserver;

constructor(private readonly renderer: Renderer2, private readonly host: ElementRef<HTMLElement>, ngZone: NgZone) {
ngZone.runOutsideAngular(() => {
new ResizeObserver(() => this.addOrRemoveTabIndex()).observe(this.host.nativeElement);
this.observer = new ResizeObserver(() => this.addOrRemoveTabIndex());
this.observer.observe(this.host.nativeElement);

this.unlisteners.push(
this.renderer.listen(this.host.nativeElement, 'mouseup', () => {
Expand All @@ -39,6 +41,9 @@ export class ClrModalBody implements OnDestroy {
while (this.unlisteners.length) {
this.unlisteners.pop()();
}

this.observer.disconnect();
this.observer = null;
}

private addTabIndex() {
Expand Down

2 comments on commit b95729e

@cwilson
Copy link

@cwilson cwilson commented on b95729e May 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @coryrylan, I'd like to request that this change be ported back to the v12 branch. Should I open an issue?

@kevinbuhmann
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cwilson: See #135.

Please sign in to comment.