Repository navigation
Conversation
The web component's toggle button set aria-controls="gov-banner-default", but no element in its shadow root had that id, so the reference pointed at nothing. Give the content region that id so the reference resolves inside the same shadow root, matching the classic banner markup. Derive the content's hidden state from isOpen instead of toggling the attribute by hand, so aria-expanded and the content's visibility always agree, including when isOpen is set directly.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @ryparker — thanks for your contribution! There is one thing that may be holding this up: for security reasons, USWDS requires that all commits to this repo have a verified commit. The following commit(s) on this PR aren't verified:
Here's what's needed:
Please let us know if you have any questions. We appreciate your help here. This comment will update automatically once your commits are verified. |
Summary
Fixed the
<usa-banner>web component so its toggle button points to the content it opens. The button'saria-controlsnow resolves to the banner content inside the component, and the button's expanded state always matches whether that content is showing.Breaking change
This is not a breaking change. Default rendering, styles, and click behavior are unchanged. See the note on
isOpenunder Solution.Related issue
No open issue tracks this. Related work:
aria-controlsinside a shadow root.Related pull requests
None. No documentation site change is needed.
Problem statement
The web component banner's "Here's how you know" button has
aria-controls="gov-banner-default", but nothing inside the component has that id. The button and the content both live in the component's shadow root, so the reference can only resolve there, and it resolves to nothing. Assistive technology that usesaria-controlsto describe or move to the controlled region can't find it, and automated checkers such as axe report the broken reference whenever the banner is expanded.The same code path had a second mismatch. The component keeps its open state in
isOpenand uses it foraria-expandedand the expanded header style, but it showed and hid the content by toggling thehiddenattribute separately. WhenisOpenwas set directly, for example with<usa-banner isopen>, the button reported "expanded" while the content stayed hidden. Witharia-controlsworking, that mismatch would point people to hidden content.This affects screen reader and other assistive technology users on every page of any site that uses the
<usa-banner>web component, since the banner sits at the top of each page.Solution
id="gov-banner-default". It shares a shadow root with the button, so the existingaria-controlsvalue now finds it. The button's markup does not change, and the id matches the classic banner. Each banner has its own shadow root, so the id doesn't collide when a page has more than one banner or also has a classic banner.hiddenattribute toisOpen, and reducedtoggle()to flippingisOpen.aria-expanded, the expanded header style, and the content's visibility now come from the same value.aria-controlsresolves to the content within the component, that two banners on one page keep their references separate, and thataria-expandedmatches the content's visibility whenisOpenis set as a property or as an attribute.A plain id reference works here because the button and the content are in the same shadow root, so this doesn't need cross-root ARIA, which browsers don't fully support yet.
One behavior change: setting
isOpendirectly now actually opens the content. Before, it only changed the header style andaria-expanded.isOpenisn't documented as an attribute, so this fixes a bug rather than changing the API.AI disclosure
What AI tools did you use to create this MR?
Author's checklist
Testing and review
npm run build, then loaddist/components/usa-banner.js.mjson a page that contains<usa-banner></usa-banner>.aria-controlsvalue should match theidon.usa-banner__content.aria-expandedshould switch betweentrueandfalseas the content shows and hides.<usa-banner isopen></usa-banner>. It should render open, witharia-expanded="true". Ondevelop, the button reports expanded while the content stays hidden.