-
-
Notifications
You must be signed in to change notification settings - Fork 238
Open
Labels
a11yRelated to accessibility and inclusionRelated to accessibility and inclusionfrontFrontend, DesignFrontend, Design
Description
The use of the listbox pattern for the README table of contents (TOC) is both broken for assistive tech and, in my opinion, the wrong tool for the task.
Instead, we should use a button with an associated popover that has a list of links. The markup would look something like this:
<!-- “navigation” landmark labelled “README table of contents” -->
<nav aria-labelledby=readme-toc-toggle>
<button id=readme-toc-toggle popovertarget=readme-toc popovertargetaction=toggle>
README table of contents<!-- visually hidden with the icon -->
</button>
<!-- I don’t think we need to label the list as the context would make it redundant -->
<ul id=readme-toc popover>
<li><a href=#user-content-nuxt aria-current=true>Nuxt</a><!-- current hash-matching link -->
<li><a href=#user-content-table-of-contents>Table of contents</a><!-- inception -->
<li><a href=#user-content-getting-started>🚀 Getting Started</a>
<!-- etc. -->
</ul>
</nav>There are several benefits to this approach:
- It’s more appropriate semantically and it avoids a lot of complexity for accessibility which means it’s less prone to break assistive tech.
popovertarget/popoveractionon a<button>makes it a collapse/expand button out-of-the-box (i.e. it implicitly setsaria-expandedfor us).- We can leverage
:popover-open(utility variantopen:) for styling the popover when it’s open. - We don’t need to worry about
aria-activedescendantand the complications that brings for accessibility and styling. - If we set
scroll-behavior: smoothon the:rootwe can just let the links do their thing.- It would be good to set some
scroll-marginfor the README’s headings or maybescroll-paddingon:rootwould be better?
- It would be good to set some
- All of this doesn’t require any JavaScript.
In other words, there is a lot that was being done with JS that we can just let the platform do for us.
We can reserve JS for enhancements like:
- Maybe some focus management. Popovers don’t move their focus to the popover by default, but I know that GitHub’s README TOC does do some focus trapping (i.e. so that the focus wraps from the start to the end, vice versa).
- Set
aria-current=trueon whatever link matches the hash of the page.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
a11yRelated to accessibility and inclusionRelated to accessibility and inclusionfrontFrontend, DesignFrontend, Design