question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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:

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.)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
crisbetocommented, Feb 17, 2022

Sorry for the delay, I missed the meeting last week but we did discuss it this week and we decided to implement the proposal from this issue not as an opt-in feature, but as the default behavior.

1reaction
RobertAKARobincommented, Feb 8, 2022

I agree there are some implementation details to work out. But this always comes up in accessibility testing, and so think it would be prudent to address.

Read more comments on GitHub >

github_iconTop Results From Across the Web

mat-form-field must contain a MatFormFieldControl
I had this issue. I imported MatFormFieldModule at my main module, but forgot to add MatInputModule to the imports array, like so:
Read more >
Form field - Angular Material
An interface which allows a control to work inside of a MatFormField . ... It serves as alternative token to the actual MatError...
Read more >
handle many mat-error(s) in the same mat-form-field ... - ITNEXT
The issue with the above configuration is that it's possible to have 2 error messages at the same time, but mat-form-field control reserves ......
Read more >
An Introduction to Angular Material Form-Fields - Medium
There are some components that do not work with a mat-form-field and we'll take a ... Let's take a look at the appearance...
Read more >
Material button, mat-error and mat-hint - YouTube
This video will teach how to use mat-button and also explain about mat-hint and mat-error. This video will also give you an understanding...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found