angular / angular/components

bug(MatFormFieldControl, MatInput): enable empty value for element attributes

未关闭
#33,353 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
area: many gemini-triaged P4
主要语言
TypeScript
星标
25k
派生
6.8k
平均合并
1 天 8 小时
30 天内合并 PR
91

描述

### Is this a regression?

- [x] Yes, this behavior used to work in the previous version

### The previous version in which this bug was not present was

21

### Description

Recent TypeScript 6 flashes out discrepancies in attributes declaration for html/material controls.

For MatInput, as for other controls, TypeScript doesn't allow empty (null or undefined) values.

The `required`, `placeholder`, etc. forces strict datatype while others such as `autocomplete` are optional.

Previous Angluar version 21 handled these cases correct, for example, placeholder in MatFormField.

In my view, all MatFormFieldControl attributes should be optional, to reflect HTML tag design by definition.

It's common to forward optional attributes between components that holds `undefined` value; forcing an issue when refering to HTML tag such as `input` with Angular decoration.

### Reproduction

StackBlitz link: https://stackblitz.com/edit/components-issue-starter-ffzyyuuu?file=src%2Fmain.ts
Steps to reproduce:
See errors for empty placehoder and missing maxlength.

### Expected Behavior

Attributes such as `placeholder` should accept null and undefined.

This should be common among all MatFormFieldControl implementations.

### Actual Behavior

Common attributes doesn't allow empty values.

### Environment

Angular CLI : 22.0.0
Angular : 22.0.0
Node.js : 24.16.0
Package Manager : npm 11.16.0
Operating System : win32 x64

贡献指南

打开贡献指南

调研方向

从 StackBlitz 复现开始,检查 MatInput 的 TypeScript 声明以及 issue 中提到的 MatFormFieldControl 实现。确认空 placeholder、maxlength、required 及相关属性的行为,然后添加或更新覆盖范围,使 null 和 undefined 能够保持一致地被接受。

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

评估

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

把新 issue 发到你的邮箱

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