feat(Accordion): add headingLevel prop so consumers can set the correct aria-level for item headings#3367
Open
starboyvarun wants to merge 1 commit intorazorpay:masterfrom
Conversation
…m headings Each AccordionItem's trigger was wrapped in a heading with a hardcoded aria-level="3". This meant the heading was always announced as an h3 regardless of where the Accordion appeared in the document, which breaks screen reader navigation when the accordion lives inside an h1 or h4 section. Added a headingLevel prop (1-6, default 3) to Accordion. The value flows through AccordionContext to AccordionButton.web.tsx, replacing the hardcoded 3. Existing consumers are unaffected since the default remains 3.
🦋 Changeset detectedLatest commit: 1a294d3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
✅ PR title follows Conventional Commits specification. |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 1a294d3:
|
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.
Summary
Every
AccordionItemtrigger renders inside a heading wrapper. The heading level was hardcoded to3:This means every accordion — regardless of where it sits in the page — always announces as an
<h3>. If an accordion lives inside an<h1>section, screen readers encounter heading levels that jump from 1 → 3 (skipping 2), which breaks document outline navigation. If it lives inside an<h4>section, the<h3>is actually higher in the hierarchy than its parent.The comment in the code acknowledged this:
// a11y guidelines suggest having an apt heading surround a button but heading level is hardcoded here.Fix
Added
headingLevel?: 1 | 2 | 3 | 4 | 5 | 6toAccordionProps(defaults to3). The value flows throughAccordionContexttoAccordionButton.web.tsx.The default value is
3, so existing consumers are completely unaffected.Changes
types.ts— addheadingLevel?: 1 | 2 | 3 | 4 | 5 | 6toAccordionPropswith JSDocAccordionContext.tsx— addheadingLeveltoAccordionContextStateAccordion.tsx— destructureheadingLevel = 3, include in context value anduseMemodepsAccordionButton.web.tsx— readheadingLevelfrom context, replace hardcoded3, remove stale commentTesting
headingLevelprop still rendersaria-level="3"(unchanged)<Accordion headingLevel={2}>rendersaria-level="2"on each item's heading wrapper