Skip to content

expose accordion panel headers as headings - #1367

Open
shelbylevel wants to merge 1 commit into
rstudio:mainfrom
shelbylevel:accordion-heading-semantics
Open

shelbylevel wants to merge 1 commit into
rstudio:mainfrom
shelbylevel:accordion-heading-semantics

Conversation

@shelbylevel

Copy link
Copy Markdown
Contributor

Pull Request

Fixes #1363

Problem

accordion_panel() puts its toggle button in a <div class="accordion-header">, which has no heading semantics, so screen reader users can't find panel titles with heading navigation. The WAI-ARIA Accordion Pattern expects each header button to be inside a heading.

Approach

  • Keep the <div>, because a native <h2> would appear in generated tables of contents (R Markdown, Quarto, pkgdown), and add role="heading" and aria-level="2". The button stays the heading's only child, as the pattern requires.
  • Add heading_level (1 to 6, default 2) to accordion(), so the level can match the surrounding document. It's on accordion() rather than accordion_panel() because panels in one accordion share a level.
  • Add the same argument to accordion_panel_insert() for dynamically inserted panels.
  • Set the level with children() instead of find(), so nested accordions keep their own levels.
  • Validate with check_heading_level(), whose errors name the calling function.

Known limitation

accordion_panel_insert() doesn't know which level its accordion uses, so the argument must be passed to match. A follow-up could copy aria-level from the existing headers in the client-side insert handler, which would remove the need for the argument.

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.

accordion_panel() headers are not exposed as headings

1 participant