-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(material/form-field): add MatLabel input property to change use of html <label> #27241
Comments
In the screenshot you show it looks like the label is associated with an invalid id, which seems like a separate bug. Angular Material allows custom form controls to specify their id and components like mat-select do this. However, it is a valid point that the |
Thanks @mmalerba for the input. Interestingly, you can see the same error as per my screenshot in the error generated on the mat-select example page. However, I'm not able to replicate it on a stackblitz. here is my stackblitz. Is there something else at play here? |
This bug is present everywhere, not only in your case. It's even on the stackblitz examples of the select component guide: When you open the first example in stackblitz, the console shows:
|
I'm thinking actually this is an issue with Chrome detecting this problem. @mmalerba is right that the error message is stating that there is no element with the id in the for="" element. This isn't right, as the mat-select has the correct matching id attribute. I believe Chrome may be picking up this error due to the way the element is created - maybe it picks up the error in the middle of the process of initialisation of the field - or it's a bug with how Chrome detects the error. I don't believe it would be classified as an error if the element was matching but non-labelable. I'm going to leave this feature open for the moment, but leaning towards this request not being the way to solve this. |
This issue appears for every mat-select. The reason being that the generated |
Any updates on this ? |
By adding a hidden
|
Personally I feel it's a bad idea. Your making a label for to any not visible, why not the solution proposed in the SO?
When the problem is solved, simply we'll remove the directive from all the imports places |
I mean yeah this is the solution that works but it works only now. It wont work once it gets fixed. The thing is I don't want to remember that I will have to delete this someday actually I'm sure I won't remember. I will forget it 100%. |
Hello folks, Thank you for reporting this. We prioritize accessibility issues that are a problem for users. If you have an explaination why this does not meet an a11y criteria (such as WCAG), we can consider that. Angular components doesn't have a hard requirement to cleanly pass automated accessibility checks. The reported issue in Chrome may be a false positive. Are you having accessibility or autocomplete issues in your application? Best Regards, Zach |
Adds an option to remove the `for` attribute from the `<label>` inside the form field from elements that can't be labeled. Also applies the new option to `mat-select` and `mat-date-range-picker`. This isn't an accessibility regression, because those elements were already being labeled using `aria-labelledby`. Fixes angular#27241.
) Adds an option to remove the `for` attribute from the `<label>` inside the form field from elements that can't be labeled. Also applies the new option to `mat-select` and `mat-date-range-picker`. This isn't an accessibility regression, because those elements were already being labeled using `aria-labelledby`. Fixes #27241.
) Adds an option to remove the `for` attribute from the `<label>` inside the form field from elements that can't be labeled. Also applies the new option to `mat-select` and `mat-date-range-picker`. This isn't an accessibility regression, because those elements were already being labeled using `aria-labelledby`. Fixes #27241. (cherry picked from commit 94a0834)
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Feature Description
Add an input property to MatLabel that changes the use of
<label>
into a basic div element without linking it to a control. Perhaps it could be implemented as:Use Case
When using form fields with standard 'labelable' form elements such as
<input>
and<select>
and using a<mat-label>
to label the field, the HTML specification for the<label for="x">
works very nicely. However, there are times when non-standard form elements are desirable to use, such as<mat-select>
with html formatted options, or other custom form fields that you might build yourself. In these cases when you use the<mat-label>
element, the resulting<label for="x">
generates a page error with the violation:Incorrect use of
<label for=FORM_ELEMENT>
You can leave out
<mat-label>
to work around this, however, it is a better user experience to have the floating label and to also have these form fields match the appearance and behaviour of the other fields in a form.The text was updated successfully, but these errors were encountered: