fix(cdk/text-field): fixed auto-size line-height bug at 110% zoom #32611
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix scrollbar appearing with decimal line-height values in textarea autosize
Fixes #32178
Problem
When using a
<textarea>withcdkTextareaAutosizeand a decimalline-heightvalue (e.g.,1.15), a vertical scrollbar appears even when the content fits within the view. This issue occurs at certain browser zoom levels (e.g., 110%) where fractional pixel values get truncated by the browser.The root cause is in the
_measureScrollHeight()method, which subtracts4from the measuredscrollHeightto account for the 2px top and bottom padding added by the measuring class. However, when the browser truncates fractional pixels (e.g.,20.4pxbecomes20px), subtracting4can result in a height that's slightly less than what's actually needed, causing a scrollbar to appear.Solution
Changed the subtraction value from
4to3.5in_measureScrollHeight(). This provides a small margin that accounts for fractional pixel truncation, preventing scrollbars from appearing when using decimal line-height values.Changes
src/cdk/text-field/autosize.ts: Changed subtraction value from4to3.5in_measureScrollHeight()methodsrc/cdk/text-field/autosize.spec.ts: Added test'should not show scrollbar with decimal line-height values at 110% zoom'that verifies the fix and would fail if the value was4Testing
4, ensuring the fix is properly validatedImpact