Skip to content

Commit b72bd27

Browse files
authored
perf(module:mention): do not run change detection when the dropdown cannot be closed (#7146)
1 parent 9a8d794 commit b72bd27

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

components/mention/mention.component.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,19 +381,30 @@ export class NzMentionComponent implements OnDestroy, OnInit, AfterViewInit, OnC
381381
}
382382

383383
private subscribeOverlayOutsideClick(): Subscription {
384-
return merge<MouseEvent | TouchEvent>(
385-
this.overlayRef!.outsidePointerEvents(),
386-
fromEvent<TouchEvent>(this.ngDocument, 'touchend')
387-
).subscribe((event: MouseEvent | TouchEvent) => {
384+
const canCloseDropdown = (event: MouseEvent | TouchEvent): boolean => {
388385
const clickTarget = event.target as HTMLElement;
389-
if (
386+
return (
390387
this.isOpen &&
391388
clickTarget !== this.trigger.el.nativeElement &&
392389
!this.overlayRef?.overlayElement.contains(clickTarget)
393-
) {
394-
this.closeDropdown();
395-
}
396-
});
390+
);
391+
};
392+
393+
const subscription = new Subscription();
394+
395+
subscription.add(
396+
this.overlayRef!.outsidePointerEvents().subscribe(event => canCloseDropdown(event) && this.closeDropdown())
397+
);
398+
399+
subscription.add(
400+
this.ngZone.runOutsideAngular(() =>
401+
fromEvent<TouchEvent>(this.ngDocument, 'touchend').subscribe(
402+
event => canCloseDropdown(event) && this.ngZone.run(() => this.closeDropdown())
403+
)
404+
)
405+
);
406+
407+
return subscription;
397408
}
398409

399410
private attachOverlay(): void {

0 commit comments

Comments
 (0)