Avoid ValidatedFieldComponent missing aria-describedby references#7484
Merged
Avoid ValidatedFieldComponent missing aria-describedby references#7484
Conversation
changelog: Bug Fixes, Accessibility, Fix missing ID references for field descriptors
Inspired by @svalexander's idea in #7488 Co-Authored-By: Shannon A <20867088+svalexander@users.noreply.github.com>
May want to revisit. Could also consider ":empty" pseudo-selector
NavaTim
reviewed
Dec 15, 2022
app/javascript/packages/validated-field/validated-field-element.ts
Outdated
Show resolved
Hide resolved
app/javascript/packages/validated-field/validated-field-element.ts
Outdated
Show resolved
Hide resolved
Avoid describedby associated to a label (which would be labelledby)
This reverts commit d12c08a.
Previously, I picked "month" as an arbitrary field to find the error, but since now the field validity aria-describedby is managed per-field, the relationship would happen at the field level. We can (and ideally should) check the accessible description for the field we're interested in checking.
technically not an issue, but we should avoid having "empty" id refs be considered
we could revert to what existed previously with "not_to have_css", but stronger guarantee that we check both the text is empty, and that it's explicitly present but not visible
This was referenced Dec 16, 2022
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎫 Ticket
Resolves LG-7579
🛠 Summary of changes
The changes here seek to improve the accessibility of ValidatedFieldComponent by avoiding assignment of
aria-describedbyID references which aren't present on the page.I noticed in a recent aXe run of our homepage that an issue is flagged for "ARIA attributes must confirm to valid values". This is not flagged by our automated feature specs for accessibility, despite using the same underlying aXe tooling (even after upgrading). It may be that the browser extension is ahead of the RSpec integration.
Previously, it was intentional that the ID references were assigned even if the elements were not present, so that the ID reference would be used in creating the element in JavaScript for displaying an error message if a field becomes invalid. It was assumed that the absence of the element corresponding to the ID would be ignored, which was the desired effect, and which appeared to be the case in testing. It's quite likely that the issue being flagged is primarily accounting for a situation where a description is expected to be present. Regardless, we should aim to avoid any issues being identified in scans.
An additional issue is being fixed here: Previously, when a field become valid again after previously being invalid, we would hide the error message by assigning a
display: none;style. While this would visually hide the error message, the message would continue to be used as the computed accessible description of the field, sincearia-describedbydoes not ignore elements which are hidden†. (cc @NavaTim I recall this being added forMemorableDateComponentbehaviors, and I'd want to double-check there are no regressions in the behavior of what it had been added for)† Source: https://www.w3.org/TR/accname-1.1/#mapping_additional_nd_te
📜 Testing Plan
aria-describedbyunless it is described by either a hint or an error messagearia-describedbyaria-describedbycorresponding to the example hintnovalidatethe page'sformelement and then submit the form, the subsequent page should havearia-describedbycorresponding to the initial page-rendered field error