Skip to content

Commit fe27339

Browse files
CorentinDeBoissetcrisbeto
authored andcommitted
fix(cdk/text-field): avoid page jump on auto-resize (#32605)
When we measure the size of the autosize textarea, we make it temporarily smaller which can cause the scroll position to shift. These changes add a workaround that assign a temporary margin-bottom while measuring. Fixes #23834 (cherry picked from commit c62c64f)
1 parent 0bc21f2 commit fe27339

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/cdk/text-field/autosize.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,14 @@ export class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
237237
const element = this._textareaElement;
238238
const previousMargin = element.style.marginBottom || '';
239239
const isFirefox = this._platform.FIREFOX;
240-
const needsMarginFiller = isFirefox && this._hasFocus;
240+
const needsMarginFiller = this._hasFocus;
241241
const measuringClass = isFirefox
242242
? 'cdk-textarea-autosize-measuring-firefox'
243243
: 'cdk-textarea-autosize-measuring';
244244

245-
// In some cases the page might move around while we're measuring the `textarea` on Firefox. We
245+
// In some cases the page might move around while we're measuring the `textarea`. We
246246
// work around it by assigning a temporary margin with the same height as the `textarea` so that
247-
// it occupies the same amount of space. See #23233.
247+
// it occupies the same amount of space. See #23233 and #23834.
248248
if (needsMarginFiller) {
249249
element.style.marginBottom = `${element.clientHeight}px`;
250250
}

0 commit comments

Comments
 (0)