angular / angular/components

bug(cdkTextareaAutosize): Textarea does not size to fit with initial value until window is resized

未关闭
#30,652 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
area: cdk/text-field P3
主要语言
TypeScript
星标
25k
派生
6.8k
平均合并
1 天 8 小时
30 天内合并 PR
91

描述

### 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

贡献指南

打开贡献指南

调研方向

首先运行链接的 StackBlitz 复现,并检查 cdkTextareaAutosize 指令在具有初始 ngModel 值且 cdkAutosizeMaxRows 设置为 5 时的行为。确认无需调整窗口大小即可显示全部五行,并且不会出现滚动条,这与 issue 中描述的预期行为一致。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
frontend
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。