angular / angular/components

Allow mat-error in mat-form-field subviews

オープン
#15,778 コメント 0 件 リアクション 11 件 担当者 0 名 GitHub で見る
area: material/form-field P3
主要言語
TypeScript
スター
25k
フォーク
6.8k
平均マージ
1日 8時間
マージ済み PR(30日)
91

説明

#### What is the expected behavior?
**NOTE**: it's more of an improvement (but a really critical one) than a bug.

`mat-error` should work even if it's not used as direct child of `mat-form-field`. It should work if it's used inside a component which itself is used in `mat-form-field`.

This is particularly necessary for **handling error messages in a reusable component**.
A real-world application may have several forms with a lot of validators on their fields.
Repeating a bunch of `mat-error`s and corresponding error messages for each usecase is just tedious.

### Suggested solution
I think the reason this currently doesn't work is because `@ContentChildren` decorator is used to get a hold of `mat-error` instances. However `@ContentChildren` [doesn't work for nested components](https://github.com/angular/angular/issues/5241) and aparently [this is by design](https://github.com/angular/angular/issues/5241#issuecomment-156841935).
Instead of using `@ContentChildren` , `MatError` can inject `MatFormField` and register itself into it.

#### What is the current behavior?
`mat-error` only works if it's directly used inside `mat-form-field`. If it's used inside a nested component, it doesn't work as expected.

#### What are the steps to reproduce?
https://stackblitz.com/angular/kllvoljyoem

#### Which versions of Angular, Material, OS, TypeScript, browsers are affected?
@angular/cdk@7.3.0
@angular/material@7.3.0
Angular: 7.2.3

#### Is there anything else we should know?

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

リンクされた StackBlitz の再現から始め、mat-form-field がネストされた再利用可能なコンポーネントをまたいで mat-error のインスタンスをどのように検出するかを調べます。現在の直接の子要素に限定された制限を確認し、mat-error がネストされている場合にバリデーションエラーが表示されること、また既存の直接の子要素に対する動作が維持されることを検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
angular, typescript
領域
frontend
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。