Accordion
: make toggle button names unique
#2383
Merged
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.
π Summary
If merged, this PR would update the accordion toggle to make the button names unique.
π οΈ Detailed description
To make
aria-label
not required on each item but still create unique labels for the toggle buttons, I decided to usearia-labelledby
.aria-labelledby
is set to the id of the wrapper around the toggle block and I removed thearia-label
default value. This makes it so the accessible name is just the title of the accordion.If the developer passes an
aria-label
to the accordion item,aria-labelledby
isn't set.NOTE:
I used to have a different implementation where I also included a visually hidden piece of text that said "Expand" so the button name would be "Expand {title}", but after discussing with @MelSumner we decided that wasn't even necessary because the fact that it shows/hide content is implied by
aria-expanded
. When you navigate to the button with VoiceOver it says "{title}, collapsed, button" and then when you press the button it says "expanded". this makes including the word "expand" in the button name redundnant.πΈ Screenshots
DOM after changes:
π External links
Jira ticket: HDS-3809
π Component checklist
π¬ Please consider using conventional comments when reviewing this PR.