angular / angular/components

feat(mat-form-field): Option to allow MatHint to persist alongside MatError

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

説明

### Feature Description

On every Angular Material project I've worked on, our accessibility team has flagged that the `mat-hint` disappears when `mat-error` appears. To be accessible, it is required that the `mat-hint` continues to persist somehow. Currently, the `mat-hint` element is fully removed from the DOM: https://github.com/angular/components/blob/master/src/material/form-field/form-field.html#L83

This has been brought up on SO several times:
- https://stackoverflow.com/questions/60185384/keep-the-displaying-of-both-error-and-hint-if-error
- https://stackoverflow.com/questions/47166694/angular-material-input-with-hint-text-and-error-text-at-the-same-time

To compensate, on each project we:

1. Write a wrapper component around `MatLabel`, `MatHint`, and `MatError`, as well as `MatInput`, `MatSelect`, `MatCheckbox`, etc, duplicating all of their inputs, or
2. Write a wrapper component around `MatLabel`, `MatHint`, and `MatError`, using content projection for the form controls, which breaks the synchronization between all the elements.

Either way, we spend a lot of time on ugly hacks with which we are always ultimately unsatisfied.

I propose we hide `mat-hint` with CSS (e.g. `display: none`) instead of fully removing it from the DOM. This will allow users to easily continue to persist `mat-hint` as they see fit, simply by overriding the CSS.

(Alternatively, or in addition, we could add e.g. `@Input('persistHint')` to `mat-form-field`, but this would require more of a reworking of `mat-form-field`'s logic, and would also require making some design decisions about how `mat-hint` should look when displayed alongside errors, for which the Material guidelines don't give instruction AFAIK.)

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

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

調査の方向性

まず、リンクされたヒントのレンダリング箇所にある src/material/form-field/form-field.html を読み、現在 MatHint と MatError がどのように連携されているかを確認します。提案されている CSS による永続化アプローチと、代替の persistHint input を比較し、続いて両方を表示するために必要な設計上の判断を特定します。選択した動作が現在の DOM の削除なしで実装され、関連する form-field テストでカバーされていれば完了です。

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

評価

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

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

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