Skip to content

feat(ToggleDetails): add asHeading prop to wrap toggle in h2 element - #2771

Open
islamhany528 wants to merge 3 commits into
masterfrom
bugfix/NGC-155-Notebook-page-group-toggles-aren't-headings
Open

islamhany528 wants to merge 3 commits into
masterfrom
bugfix/NGC-155-Notebook-page-group-toggles-aren't-headings

Conversation

@islamhany528

Copy link
Copy Markdown
Contributor

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)

  1. Heading markup: inspect the "Heading" example. The toggle button should sit inside an <h2>. Other examples should have no <h2>.
  2. Variants: set asHeading on each combination and confirm the toggle is wrapped in an h2:
    • variant="default"
    • variant="filled"
    • href set
    • iconPosition="start" and iconPosition="end"
    • size small, medium and large
    • fluidWidth

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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 h2 when 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

Comment thread packages/ui-toggle-details/src/ToggleDetails/v2/props.ts
Comment thread packages/ui-toggle-details/src/ToggleDetails/v2/index.tsx Outdated
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.2

QR code for preview link

🚀 View preview at
https://instructure.design/pr-preview/pr-2771/

Built to branch gh-pages at 2026-10-30 08:19 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@matyasf
matyasf requested review from matyasf and removed request for mostafatourad-inst October 29, 2026 14:38

@matyasf matyasf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why just h2? This is a reusable component, others might need different heading value

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure I will add more options to include not just h2

@matyasf matyasf self-assigned this Oct 29, 2026
@matyasf
matyasf requested review from joyenjoyer and matyasf October 30, 2026 09:48

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants