Skip to content

Commit 7ce50b3

Browse files
authored
fix(module:select): do not run tick when scrolling to activated value (#8159)
1 parent a821c62 commit 7ce50b3

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

components/select/option-container.component.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44
*/
55

66
import { CdkVirtualScrollViewport } from '@angular/cdk/scrolling';
7+
import { isPlatformBrowser } from '@angular/common';
78
import {
89
AfterViewInit,
910
ChangeDetectionStrategy,
1011
Component,
1112
EventEmitter,
1213
Input,
14+
NgZone,
1315
OnChanges,
1416
Output,
17+
PLATFORM_ID,
1518
SimpleChanges,
1619
TemplateRef,
1720
ViewChild,
18-
ViewEncapsulation
21+
ViewEncapsulation,
22+
inject
1923
} from '@angular/core';
2024

2125
import { NzSafeAny } from 'ng-zorro-antd/core/types';
@@ -92,8 +96,8 @@ export class NzOptionContainerComponent implements OnChanges, AfterViewInit {
9296
@Output() readonly scrollToBottom = new EventEmitter<void>();
9397
@ViewChild(CdkVirtualScrollViewport, { static: true }) cdkVirtualScrollViewport!: CdkVirtualScrollViewport;
9498
private scrolledIndex = 0;
95-
96-
constructor() {}
99+
private ngZone = inject(NgZone);
100+
private platformId = inject(PLATFORM_ID);
97101

98102
onItemClick(value: NzSafeAny): void {
99103
this.itemClick.emit(value);
@@ -128,7 +132,10 @@ export class NzOptionContainerComponent implements OnChanges, AfterViewInit {
128132
this.scrollToActivatedValue();
129133
}
130134
}
135+
131136
ngAfterViewInit(): void {
132-
setTimeout(() => this.scrollToActivatedValue());
137+
if (isPlatformBrowser(this.platformId)) {
138+
this.ngZone.runOutsideAngular(() => setTimeout(() => this.scrollToActivatedValue()));
139+
}
133140
}
134141
}

0 commit comments

Comments
 (0)