angular / angular/components

bug(mat-date-range-input): formGroup error doesn't switch form field error state

未关闭
#29,410 2 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

area: material/datepicker 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

Hello,

https://material.angular.io/components/datepicker/overview#date-range-input-forms-integration
The mat date range input documentation states:

Date range input forms integration

The mat-date-range-input component can be used together with the FormGroup directive from @angular/forms to group the start and end values together and to validate them as a group.

So I'm expecting the form group, grouping start and end date, to update the "global range input" state, but this is not the case.

My use case is to add a customValidator (to limit the number of days between start and end dates) on the formGroup. When the form is in error, I was expecting the form field to be red and to display mat-error, but nothing shows when the form is invalid.

  • Is it a bug?
  • Is it the normal behavior, and a documentation ambiguity? It would be a nice new feature in this case.

I've found a workaround using ErrorStateMatcher. But it feels like it's supposed to be included in mat date range picker as both inputs are inside, within the formGroup
https://material.angular.io/components/input/overview#changing-when-error-messages-are-shown

Reproduction

Have mat date range picker with a form group validator => only start and end controls are updating displayed form field validity

Reproduction link: https://stackblitz.com/edit/stackblitz-starters-xhx4k1?file=src%2Fmain.ts

Expected Behavior

When formGroup is in error, form field state should be in error and display mat-error

Actual Behavior

When formGroup is in error, form field state is valid and no mat-error is displayed

Environment
  • Angular: 18
  • CDK/Material: 18

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

打开链接的 StackBlitz 复现,并先阅读 date-range input forms 集成文档。跟踪 form-group validator 如何影响 date-range 字段的错误状态;当无效组将字段标记为错误并显示 mat-error,而有效组保持不变时,即表示完成。

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

评估

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

把新 issue 发到你的邮箱

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