Skip to content

fix(cdk/text-field): defer autosize checks until view initialization - #34136

Open
nagahara-naoki wants to merge 1 commit into
angular:mainfrom
nagahara-naoki:fix-textarea-autosize-initial-line-height
Open

nagahara-naoki wants to merge 1 commit into
angular:mainfrom
nagahara-naoki:fix-textarea-autosize-initial-line-height

Conversation

@nagahara-naoki

Copy link
Copy Markdown
Contributor

Summary

CdkTextareaAutosize can cache the textarea line height during its first ngDoCheck, before dynamic host classes have been applied. With matInput inside mat-form-field, this means measuring the browser default font instead of the inherited font. The resulting minimum and maximum heights remain incorrect until a window resize clears the cache.

Skip automatic checks until the view has initialized, allowing the existing ngAfterViewInit resize to perform the initial measurement after host bindings have been applied.

For example, a textarea with a 50px line height and limits of 2–5 rows now starts with min-height: 100px and max-height: 250px.

Fixes #33944.

Testing

Added regression tests for both a CDK textarea with a dynamic host class and a matInput textarea inside mat-form-field.

  • Without the fix: both new tests fail; the existing 130 tests pass.
  • With the fix: all 132 tests pass in Chromium (28 CDK text-field and 104 Material input tests).
  • Existing coverage includes initial content and placeholder sizing, row limits, programmatic value changes, window resizing, and disabling/re-enabling autosize.
  • Repository formatting applied to all changed files.
pnpm bazel test //src/cdk/text-field:unit_tests_chromium //src/material/input:unit_tests_chromium --test_output=errors

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(cdk/text-field): cdkTextareaAutosize caches line height before matInput applies font: inherit, so min/max rows are wrong

1 participant