components icon indicating copy to clipboard operation
components copied to clipboard

mat-error is not making aria-live announcements

Open jelbourn opened this issue 8 years ago • 8 comments

MatError has role="alert" applied, but this won't take effect when it's appended to the DOM. We need to either:

  • Change <mat-error> to always be in the DOM (display: none) and show it when a form-field goes into error-state, or
  • Use the LiveAnnouncer service to announce the contents (as an alert) when the control goes into an error state.

jelbourn avatar Nov 02 '18 23:11 jelbourn

The first solution is tricky, because we don't have control over when the errors are displayed. It's up to the consumer to add the mat-error and toggle it using ngIf or display.

crisbeto avatar Nov 04 '18 11:11 crisbeto

This might actually not be necessary- I got some more information about how role="alert" actually is supposed to behave differently from aria-live. I need to do some more follow-up to see if we need to make a change.

jelbourn avatar Nov 06 '18 18:11 jelbourn

Related to #14281

jelbourn avatar Nov 26 '18 22:11 jelbourn

@jelbourn posting this here because it is related. Please let me know if you want me to create a separate issue for this.

aria-describedby has poor support when referencing an element with role="alert". Most screen reader / browser combinations will not announce the error message at all when the input receives focus. This might make it difficult for screen reader users to discover error messages as they navigate back through the form.

It's not clear if this is by design in the ARIA spec or if this due to a browser bug. See

Suggest using aria-live="assertive" and aria-atomic="true" instead of role="alert". This will accomplish the same thing and fix the issue mentioned above. Another possible solution is to use <mat-error [attr.role]="'presentation'" [attr.aria-live]="'assertive'" [attr.aria-atomic]="'true'"> to acheive the same functionality.

mfairchild365 avatar Apr 23 '19 13:04 mfairchild365

@mfairchild365 - I feel that since we are associating the input field with the error message using the aria-describedby attribute, we don't need to live region on the inline error message. I have had an opportunity working with users to do Usability testing on forms. One thing we inferred from that is, 70% of the users felt that the announcement of the error messages as live regions were jarring/annoying. The reasoning behind that is that, assistive technology users reported that they navigate through all the input fields first to get the feel of what is expected out of the form before they start filling out. Announcement of the message for every tab was jarring/annoying for them.

With that being said, if you really want to communicate the error messages as live regions, it is recommended by W3C to use aria-live="polite" rather than role="alert" which implicitly corresponds to aria-live="assertive" and aria-atomic="true". Please find the link as reference. (https://www.w3.org/WAI/tutorials/forms/notifications/)

Note: The displayed message in this example is coded using a element that has an aria-live attribute with the value polite. The contents of this so called “live region” are conveyed to screen readers and other assistive technology. The value “polite” de-emphasizes the importance of the message and does not cause screen readers to interrupt their current tasks to read aloud this message. Thus the message is only read once when the user stops typing rather than on every keystroke that the user makes.

PS: Unfortunately, since the Usability study is a proprietary property of my company, I can't share any links here.

ramjiseetharaman avatar Nov 27 '20 17:11 ramjiseetharaman

Got an update with reference to the Usability study I was talking about. Here is the link to the study I am talking about, https://simplyaccessible.com/article/accessible-forms-angular/

ramjiseetharaman avatar Nov 29 '20 21:11 ramjiseetharaman

closing because I believe this has been fixed by #21870

zarend avatar Jul 08 '21 16:07 zarend

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.