-
Couldn't load subscription status.
- Fork 6.8k
Description
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
No response
Description
When using a <textarea> with cdkTextareaAutosize and a decimal numeric line-height value (for example 1.15), a vertical scrollbar appears even when the content fits perfectly within the view.
This happens despite autosizing being enabled, and the field should automatically expand to fit content without a scrollbar.
This issue does not occur when line-height is an integer (e.g. 1 or 2).
Technical Observation
The browser appears to truncates decimal values internally (e.g. from 16.08 px to 16 px) when returning the clone's height to Angular.
As a result, when the text area expands to its autosized height (e.g. 4 lines), the truncation introduces a small pixel mismatch, just enough to trigger a scrollbar.
Possible solution:
Angular CDK might need to account for fractional pixel rounding when computing textarea height.
Reproduction
StackBlitz link: https://stackblitz.com/edit/5xmbl7sj-53y6s3u8?file=src%2Fexample%2Ftext-field-autosize-textarea-example.html
Steps to reproduce:
- Open the StackBlitz link above
- Set the browser zoom to
110%(important) - Observe the
<textarea>component withcdkTextareaAutosize - Notice the CSS rule applied
textarea { line-height: 1.15 }- Fill in three lines of text, e.g. using
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- Add one more character (
a),
-> A scroll bar appears even though the text area expands correctly
Expected Behavior
The textarea should never display a scrollbar when autosizing is enabled, regardless of line-height precision.
It should fully expand to fit content, even when line-height includes decimal or sub-pixel values.
Actual Behavior
A vertical scrollbar appears after the text fills exactly three lines and one additional character is entered.
The scrollbar is triggered despite autosizing correctly adjusting the height.
Environment
- Angular:
20.2.4 - CDK/Material:
20.2.2 - Browser(s):
Edge (141.0.3537.85), Chrome (141.0.7390.108)possibly more (tested on these) - Operating System (e.g. Windows, macOS, Ubuntu):
Windows