Skip to content

Commit

Permalink
perf(module:mention): do not run change detection when the dropdown c…
Browse files Browse the repository at this point in the history
…annot be closed (#7146)
  • Loading branch information
arturovt committed Feb 22, 2022
1 parent 9a8d794 commit b72bd27
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions components/mention/mention.component.ts
Expand Up @@ -381,19 +381,30 @@ export class NzMentionComponent implements OnDestroy, OnInit, AfterViewInit, OnC
}

private subscribeOverlayOutsideClick(): Subscription {
return merge<MouseEvent | TouchEvent>(
this.overlayRef!.outsidePointerEvents(),
fromEvent<TouchEvent>(this.ngDocument, 'touchend')
).subscribe((event: MouseEvent | TouchEvent) => {
const canCloseDropdown = (event: MouseEvent | TouchEvent): boolean => {
const clickTarget = event.target as HTMLElement;
if (
return (
this.isOpen &&
clickTarget !== this.trigger.el.nativeElement &&
!this.overlayRef?.overlayElement.contains(clickTarget)
) {
this.closeDropdown();
}
});
);
};

const subscription = new Subscription();

subscription.add(
this.overlayRef!.outsidePointerEvents().subscribe(event => canCloseDropdown(event) && this.closeDropdown())
);

subscription.add(
this.ngZone.runOutsideAngular(() =>
fromEvent<TouchEvent>(this.ngDocument, 'touchend').subscribe(
event => canCloseDropdown(event) && this.ngZone.run(() => this.closeDropdown())
)
)
);

return subscription;
}

private attachOverlay(): void {
Expand Down

0 comments on commit b72bd27

Please sign in to comment.