Skip to content
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

DisclosurePrimitive - Implement a11y toggled content pattern #2643

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

dchyun
Copy link
Contributor

@dchyun dchyun commented Jan 13, 2025

📌 Summary

This PR implements usage of the aria-controls attribute in the DisclosurePrimitive component to align show/hide behavior across the repo as follows in the initiative from HDS-3581.

The DisclosurePrimitive is leveraged in the Accordion and Reveal.

🛠️ Detailed description

Currently in the DisclosurePrimitive, the toggled content does not follow the proper a11y structure for toggled content, or leverage aria-controls in the preferred way.

As per a11y guidance in HDS-3581, all togged content should follow a pattern leveraging aria-controls, and all toggled containers should not be removed from the DOM on each toggle. They should always be present, and only the content inside them is added and removed.

Currently the DisclosurePrimitive follows a pattern where the entire content block is added and removed on each toggle, and any aria-controls attributes are set to the id of this removable block. In this PR the hds-disclosure-primitive__content block is now in the DOM at all times, and the yielded content is removed or added based on the toggle.

In this PR, in the Accordion and Reveal, the aria-controls attribute of the toggle elements are now set equal to a contentId provided by the DisclosurePrimitive. They are no longer set to the id of content inside the yielded block.

📸 Screenshots

Before - Accordion

Closed
Screenshot 2025-01-10 at 3 08 59 PM

Open
Screenshot 2025-01-10 at 3 09 14 PM

After - Accordion

Closed
Screenshot 2025-01-10 at 3 16 11 PM

Open
Screenshot 2025-01-10 at 3 16 23 PM

🔗 External links

Jira ticket: HDS-4324


👀 Component checklist

💬 Please consider using conventional comments when reviewing this PR.

Copy link

vercel bot commented Jan 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
hds-showcase ✅ Ready (Inspect) Visit Preview Jan 13, 2025 7:52pm
hds-website ✅ Ready (Inspect) Visit Preview Jan 13, 2025 7:52pm

@dchyun dchyun marked this pull request as ready for review January 13, 2025 15:21
@dchyun dchyun requested a review from a team as a code owner January 13, 2025 15:21
@dchyun dchyun changed the title Disclosure Primitive - Implement a11y toggled content pattern DisclosurePrimitive - Implement a11y toggled content pattern Jan 13, 2025
Copy link
Contributor

@shleewhite shleewhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but we should definitely test this in products before we ship. Last year we changed something similar-ish in Dropdown and it broke tests (and led us to add @preserveContentInDom):

{{#if (or PP.isOpen @preserveContentInDom)}}
)

@dchyun
Copy link
Contributor Author

dchyun commented Jan 13, 2025

This looks good, but we should definitely test this in products before we ship. Last year we changed something similar-ish in Dropdown and it broke tests (and led us to add @preserveContentInDom):

{{#if (or PP.isOpen @preserveContentInDom)}}

)

Tested the changes across atlas and cloud-ui and didn't run into any test failures. But I think this is an open question if these kind of DOM changes could be considered breaking or not. @alex-ju do you see any potential issues with this or think it could possibly be a breaking change based on your recent RFC?

Similar DOM changes will have to be made for the hds-tooltip updates, so can follow whatever we decide here on that as well.

</div>
{{#if this.isOpen}}
<div class="hds-disclosure-primitive__content">
<div class="hds-disclosure-primitive__content" id={{this._contentId}}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could a breaking change if consumers use hds-disclosure-primitive__content selector to check if disclosed content is visible or not. If we find through testing that it does not affect tests then we're good. Otherwise we'd either have to find another way or defer this feature to a major release.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree it could be seen as breaking. I tested it out in atlas locally and ran it through tests in cloud-ui and nothing seems to be breaking, but not sure about other consumers.

Copy link
Member

@alex-ju alex-ju Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smoke testing sounds good. Searching for this class being used as a selector I could only find a few instances in one test in nomad. I would try and check that test suite and if it's all good we can consider releasing this as a patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests seem to pass for me. If anything it may make the test they have never fail. They are testing that hds-disclosure-primitive__content is present on the page, and with the new approach it will always be present and only the inner content will be added / removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Thanks for checking! On that basis we can class it as a patch indeed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went back through this after I realized my changes from the testing branch weren't updating the dist for local testing in Nomad. There does seem to be a test failure now on that test you highlighted. The test is related to a component they have that uses a reveal inside of a dropdown. So we may have to hold off on this change...

Screenshot 2025-01-15 at 8 54 44 PM

Copy link
Member

@alex-ju alex-ju Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can hold this PR for now and work it from another angle. Maybe we can update their tests to not need this class, then get this change in. Otherwise, as you mentioned in the sister PR, we can roll it out in a major.

@dchyun dchyun marked this pull request as draft January 16, 2025 18:30
@dchyun
Copy link
Contributor Author

dchyun commented Jan 16, 2025

Converted back to a draft pr until issues with failing tests in consumer's repos can be sorted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants