-
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
fix(material/input): only set as aria-invalid if the input isn't empty #21609
Conversation
Only sets `aria-invalid` on a `MatInput` if it is invalid and it has a value, otherwise it'll likely overlap with `aria-required` and cause more noise for users. Furthermore, it may be confusing if the user lands on an input that they haven't interacted with, but it's already invalid. Fixes angular#18140.
51991b9
to
42556d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @zelliott
'[attr.aria-required]': 'required.toString()', | ||
// Only mark the input as invalid for assistive technology if it has a value since the | ||
// state usually overlaps with `aria-required` when the input is empty and can be redundant. | ||
'[attr.aria-invalid]': 'errorState && !empty', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify- will errorState
be true
when the control is touched (not pristine)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The errorState
is set based on the ErrorStateMatcher
. The default one will be true if the input is invalid and touched or the form has been submitted.
From #18140:
Sounds alright to me. I took a look at WCAG for any guidance (here's the relevant technique: https://www.w3.org/WAI/WCAG21/Techniques/aria/ARIA21) and stumbled upon two different examples:
The second example shows that there is WCAG precedent for omitting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@crisbeto or @jelbourn We have some internal tests that check this exact behavior. E.g. it('displays an error when input is empty', () => {
setInputValue(input, '');
expect(input.getAttribute('aria-invalid')).toBe('true');
}); Is it ok to delete these tests entirely or should we change how they're checking the inputs' error state? |
@wagnermaciel the test should ideally be updated to reflect the new behavior |
@jelbourn What is the new correct way to check an inputs error state? |
Probably updating the test to not have |
#21609) Only sets `aria-invalid` on a `MatInput` if it is invalid and it has a value, otherwise it'll likely overlap with `aria-required` and cause more noise for users. Furthermore, it may be confusing if the user lands on an input that they haven't interacted with, but it's already invalid. Fixes #18140. (cherry picked from commit d0c53ac)
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. |
Only sets
aria-invalid
on aMatInput
if it is invalid and it has a value, otherwise it'll likely overlap witharia-required
and cause more noise for users. Furthermore, it may be confusing if the user lands on an input that they haven't interacted with, but it's already invalid.Fixes #18140.