Repository navigation
feat(ToggleDetails): add asHeading prop to wrap toggle in h2 element - #2771
islamhany528 wants to merge 3 commits into
Conversation
|
|
1 similar comment
|
|
There was a problem hiding this comment.
🟡 Changes recommended
The added required heading style key is missing from generateStyle, causing a TypeScript error, and the unstyled h2 introduces spacing and typography regressions.
2 open issues
What changed in this PR
Adds an optional asHeading prop to ToggleDetails v2 so screen reader users can navigate toggle groups by heading.
Changes:
- Wraps default, filled, and link toggles in an
h2when enabled. - Documents the prop with an interactive example.
- Adds tests for heading markup and unchanged default behavior.
| File | Description |
|---|---|
packages/ui-toggle-details/src/ToggleDetails/v2/README.md |
Documents asHeading with a heading example. |
packages/ui-toggle-details/src/ToggleDetails/v2/props.ts |
Declares the prop and heading style key. |
packages/ui-toggle-details/src/ToggleDetails/v2/index.tsx |
Conditionally wraps the toggle in an h2. |
packages/ui-toggle-details/src/ToggleDetails/__tests__/ToggleDetails.test.tsx |
Tests default behavior and heading wrappers across variants. |
Review effort: Balanced
|
matyasf
left a comment
There was a problem hiding this comment.
I think this generally this change is OK (e.g. W3C recommends this pattern too -- https://www.w3.org/WAI/ARIA/apg/patterns/accordion/examples/accordion/ )
but since this is a library, we should make it customizable the heading level, for example the new prop should have a type 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' (and when the value is not set, it should not wrap stuff in a heading)
| } | ||
|
|
||
| return asHeading ? ( | ||
| <h2 css={this.props.styles?.heading}>{toggle}</h2> |
There was a problem hiding this comment.
Why just h2? This is a reusable component, others might need different heading value
There was a problem hiding this comment.
Sure I will add more options to include not just h2
…d adjust tests accordingly


Problem:
The Notebook page only has one heading, the H1 "Notebook". The page-name groups (the ToggleDetails toggles) aren't marked up as headings. That means screen reader users can't jump between groups by heading. They have to go through every note card to find the notes for a page.
WCAG: 1.3.1 Info and Relationships (Level A)
Test Plan
Manual (docs app:
pnpm run dev, ToggleDetails page, "Heading" example)<h2>. Other examples should have no<h2>.asHeadingon each combination and confirm the toggle is wrapped in anh2:variant="default"variant="filled"hrefseticonPosition="start"andiconPosition="end"sizesmall, medium and largefluidWidth