From 8bde81fb494b96cd09b8fd81ce40711b57d2ad9a Mon Sep 17 00:00:00 2001 From: Miles Malerba Date: Thu, 25 Apr 2024 14:27:17 -0700 Subject: [PATCH] fix(cdk/scrolling): move setting transform to ngAfterViewChecked --- src/cdk/scrolling/virtual-scroll-viewport.ts | 13 ++++++++----- tools/public_api_guard/cdk/scrolling.md | 2 ++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/cdk/scrolling/virtual-scroll-viewport.ts b/src/cdk/scrolling/virtual-scroll-viewport.ts index 6fa533b9784f..74d46484a9d8 100644 --- a/src/cdk/scrolling/virtual-scroll-viewport.ts +++ b/src/cdk/scrolling/virtual-scroll-viewport.ts @@ -504,6 +504,14 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On } } + ngAfterViewChecked() { + // Apply the content transform. The transform can't be set via an Angular binding because + // bypassSecurityTrustStyle is banned in Google. However the value is safe, it's composed of + // string literals, a variable that can only be 'X' or 'Y', and user input that is run through + // the `Number` function first to coerce it to a numeric value. + this._contentWrapper.nativeElement.style.transform = this._renderedContentTransform; + } + /** Run change detection. */ private _doChangeDetection() { if (this._isDestroyed) { @@ -515,11 +523,6 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On afterNextRender( () => { this._isChangeDetectionPending = false; - // Apply the content transform. The transform can't be set via an Angular binding because - // bypassSecurityTrustStyle is banned in Google. However the value is safe, it's composed of - // string literals, a variable that can only be 'X' or 'Y', and user input that is run through - // the `Number` function first to coerce it to a numeric value. - this._contentWrapper.nativeElement.style.transform = this._renderedContentTransform; const runAfterChangeDetection = this._runAfterChangeDetection; this._runAfterChangeDetection = []; for (const fn of runAfterChangeDetection) { diff --git a/tools/public_api_guard/cdk/scrolling.md b/tools/public_api_guard/cdk/scrolling.md index ca520ef4b7df..2f63423ebd81 100644 --- a/tools/public_api_guard/cdk/scrolling.md +++ b/tools/public_api_guard/cdk/scrolling.md @@ -205,6 +205,8 @@ export class CdkVirtualScrollViewport extends CdkVirtualScrollable implements On // (undocumented) static ngAcceptInputType_appendOnly: unknown; // (undocumented) + ngAfterViewChecked(): void; + // (undocumented) ngOnDestroy(): void; // (undocumented) ngOnInit(): void;