Skip to content

LG-7579 aria describedby#7488

Closed
svalexander wants to merge 6 commits intomainfrom
shannon/lg-7579-aria-describedby
Closed

LG-7579 aria describedby#7488
svalexander wants to merge 6 commits intomainfrom
shannon/lg-7579-aria-describedby

Conversation

@svalexander
Copy link
Contributor

@svalexander svalexander commented Dec 14, 2022

🎫 Ticket

Lg-7579

🛠 Summary of changes

This pr addresses two issues with the ValidatedFieldComponent. Currently when the component is first rendered the aria-describedby attribute includes "validated-field-hint-{id}" and "validated-field-error-{id}". The hint id is included even if there is not a hint, and the error id is included before an actual hint exists. These id's should not be included in aria-describedby unless the hint and error exist.
To correct the hint issue, a check is added in the validated-field-component.html.erb for the presence of the hint.
For the error issue, the error id is shown when the input is invalid (user has submitted field w/o valid input), and also adds the error id to the element that displays the error (this is to create a connection between the error element and the validated field component).

📜 Testing Plan

Provide a checklist of steps to confirm the changes.

  • Navigate to the state id form
  • run the ibm equal access accessibility checker (plugin)
  • Under "name, role, value" ensure that there is not an error about aria-describedby being invalid
  • do not enter any values in the input fields, click submit button on page
  • run scan again inn the a11y checker
  • Under "name, role, value" ensure that there is not an error about aria-describedby being invalid

@aduth
Copy link
Contributor

aduth commented Dec 14, 2022

I hadn't noticed this ticket before and stumbled onto the same automated testing finding, proposing some similar changes at #7484. I'm happy to close my pull request and/or consolidate some of the changes.

I like the idea of the server generating an ID for the <lg-validated-field> tag to use in the JavaScript. 👍

For the changes which effectively hide the description by changing the aria-describedby, was there a specific reason we couldn't empty out the error message element rather than hiding it?

…nly includes ids for errors and hints that exist
@svalexander svalexander changed the title Shannon/lg 7579 aria describedby Lg-7579 aria describedby Dec 14, 2022
@svalexander svalexander requested review from a team and sheldon-b December 14, 2022 18:00
@svalexander
Copy link
Contributor Author

svalexander commented Dec 14, 2022

For the changes which effectively hide the description by changing the aria-describedby, was there a specific reason we couldn't empty out the error message element rather than hiding it?

@aduth No specific reason, had started with the show function first and so just did the opposite of that with hide to ensure if a user corrected the error the aria-describedby wouldn't include the error id.

I was going to close out my pr since yours covered the same issue. I think it would be useful to link to the Lg-7579 ticket in yours so we can track the pr.

@aduth
Copy link
Contributor

aduth commented Dec 14, 2022

Sure, happy to continue and collaborate in #7484. I'll add a link to the ticket there. I also like the idea you implemented here with the error-id attribute, so I'll bring that over to #7484 and coauthor you on the commit for credit.

I think we may have been hiding the element since .usa-error-message has some default padding that might affect the layout. I might need to bring that back for #7484, or find some other way to make sure that the empty error message doesn't affect the page layout (maybe we remove the element after the field becomes valid again, for example).

aduth added a commit that referenced this pull request Dec 14, 2022
Inspired by @svalexander's idea in #7488

Co-Authored-By: Shannon A <20867088+svalexander@users.noreply.github.com>
aduth added a commit that referenced this pull request Dec 16, 2022
)

* Avoid ValidatedFieldComponent missing aria-describedby references

changelog: Bug Fixes, Accessibility, Fix missing ID references for field descriptors

* Fix specs

* Remove unnecessary non-null operator

* Add error-id as attribute of lg-validated-field

Inspired by @svalexander's idea in #7488

Co-Authored-By: Shannon A <20867088+svalexander@users.noreply.github.com>

* Try avoiding layout-affecting padding for empty error message

May want to revisit. Could also consider ":empty" pseudo-selector

* Make spec descriptor hint more realistic

Avoid describedby associated to a label (which would be labelledby)

* Sync MemorableDateComponent markup

See: #7484 (comment)

* Revert "Try avoiding layout-affecting padding for empty error message"

This reverts commit d12c08a.

* Update MemorableDate component to add error-id reference

* Create helper methods to consolidate logic for hint/error ID

* Restore display: none styling for valid field

* Add describedby association as part of input validity handling

* Remove accessible description assertion

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.

* Avoid excess spaces in aria-describedby

technically not an issue, but we should avoid having "empty" id refs be considered

* Assert error message as hidden

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

* Update MemorableDateComponent specs

* Remove debugging code

Co-authored-by: Shannon A <20867088+svalexander@users.noreply.github.com>
@svalexander svalexander deleted the shannon/lg-7579-aria-describedby branch December 21, 2022 20:21
@svalexander svalexander changed the title Lg-7579 aria describedby LG-7579 aria describedby May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants