bug(cdkTextareaAutosize): Textarea does not size to fit with initial value until window is resized
- Dominant language
- TypeScript
- Stars
- 25k
- Forks
- 6.8k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 91
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
Auto resize of the cdkTextareaAutosize directive for a textarea, which has an initial value bound to it, is not working.
### Reproduction
It is a fork of the "Auto-resizing textarea" example of https://material.angular.io/cdk/text-field/overview. I have just added ngModel with a initial value of 5 lines. This 5 lines should be displayed without scrolling (cdkAutosizeMaxRows is also set to 5).
StackBlitz link: https://stackblitz.com/edit/oktcnmdj
Steps to reproduce:
1. Start example
### Expected Behavior
Textarea should immediatly show all 5 lines without scrollbar, without resizing the window.
### Actual Behavior
Scrollbar is shown and only 3 lines are displayed
After resizing the window it works.
### Environment
- Angular: 19.2.3
- CDK/Material: 19.2.3
- Browser(s): chrome 134.0.6998.89
- Operating System (e.g. Windows, macOS, Ubuntu): Windows 11
Contributor guide
Research direction
Start by running the linked StackBlitz reproduction and inspect the cdkTextareaAutosize directive behavior with an initial ngModel value and cdkAutosizeMaxRows set to 5. Confirm that all five lines display without a window resize and that no scrollbar appears, matching the expected behavior described in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100