-
-
Notifications
You must be signed in to change notification settings - Fork 79.1k
Docs: improve a11y on section heading anchor links #41487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs: improve a11y on section heading anchor links #41487
Conversation
Thanks for tackling this issue 🙏 |
The HTML and the visible focus area differ slightly from what we used in Hugo, but as long as they meet accessibility standards, it’s fine with me. In Hugo: <h2 id="quick-start">Quick start <a class="anchor-link" href="#quick-start" aria-label="Link to this section: Quick start"></a></h2> In this PR: <h2 id="quick-start">Quick start<a class="anchor-link" href="#quick-start"><span class="visually-hidden">Link to this section: Quick start</span><span aria-hidden="true"> #</span></a></h2> Adding @patrickhlauke as a reviewer to double-check :) |
The problem I had with |
Yep, I ran into the exact same issue during the migration — that’s actually why I decided to postpone it. Really glad you found another approach though! 🙌 |
Well actually I just tested with the following code and it works now on Bootstrap code (not in our fork, we are behind) [
rehypeAutolinkHeadings,
{
behavior: 'append',
content: [{ type: 'text', value: ' ' }],
properties: (element: Element) => ({
class: 'anchor-link',
ariaLabel: `Link to this section: ${(element.children[0] as Text).value}`
}),
test: (element: Element) => element.tagName.match(headingsRangeRegex)
}
], After some investigation it turns out you updated the rehype plugin in this commit and the issue is now fixed. I will switch to aria-label in the PR then. |
84f32c4
to
048b4e9
Compare
Wonderful stuff...from a quick test with Chrome/NVDA, this works fine and is a great improvement over the current |
Description
Add content in
anchor-links
in the section headings of the documentation. This is an accessibility improvement to vocalise the actual text of the heading on keyboard navigation.I added 2
span
s, one with.visually-hidden
the other with.aria-hidden
to contain the # and deleted the # added in:after
pseudo-element as it was wrongly vocalized.Motivation & Context
At the moment, the # anchor link on each section heading is vocalized as "Number" without any other precision and therefore do not provide any useful information to users of assistive technologies.
Type of changes
Checklist
npm run lint
)Live previews