-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
perf(a11y): provide accessible header anchors #2040
Conversation
e75eec1
to
bb08431
Compare
Is there a way to achieve this without wrapping |
bb08431
to
adfcfe4
Compare
+1, it will break @vuejs/theme too 👀 |
Yes, but... Thank you for raising this question. It's actually quite intricate and I'll try to sum ti up to allow for further discussion (with links to more details). I can provide more details (and tests) depending on which direction we head to. Are you referring to
<h1 id="what-is-vitepress" tabindex="-1"><a class="header-anchor" href="#what-is-vitepress">What is VitePress?</h1> The only problem with this variant is, that you cannot use any links inside the "heading".
<div class="header-wrapper">
<h1 id="what-is-vitepress" tabindex="-1">What is VitePress?</h1>
<a class="header-anchor" href="#what-is-vitepress" aria-label="Permalink to "What is VitePress?"">#</a>
</div> valeriangalliat (package author) is using style I've reviewed the current semantics of MDN. This is how it looks right now: <h2 id="try_it"><a href="#try_it">Try it</a></h2> It (still) is just like permalink style However, MDN does not use permalinks with Additionally, the overall semantics of a page look slightly different, which would be even a more accessible variant. Any chances of using similar semantics with <main id="content">
<article lang="en-US">
<h1>The HTML Section Heading elements</h1>
<section aria-labeledby="try_it">
<h2 id="try_it"><a href="#try_it">Try it</a></h2>
<!-- ... -->
</section/>
<!-- ... -->
</article>
<!-- ... -->
</main> These are the semantics of VitePress rendered pages at the moment: <main>
<div>
<h1>
What is VitePress?
<a class="header-anchor" href="#what-is-vitepress" aria-hidden="true">#</a>
</h1>
<!-- ... -->
<h2>
Use Cases
<a class="header-anchor" href="#use-cases" aria-hidden="true">#</a>
</h2>
<!-- ... -->
</div>
<!-- ... -->
</main> I guess it would require also changing some of the rendering by |
Can we change it to something like what Docusaurus is doing? Example here https://docusaurus.io/docs This would preserve the same DOM structure as we have now. They use |
I think we can achieve this relatively easily with the Custom Renderer and I'll update the PR, after we find the best option. But I don't think, that it is that relevant, if the The problem how <main>
<div>
<h1>
What is VitePress?
<a class="header-anchor" href="#what-is-vitepress" aria-hidden="true">#</a>
</h1>
<!-- ... -->
<h2>
Use Cases
<a class="header-anchor" href="#use-cases" aria-hidden="true">#</a>
</h2>
<!-- ... -->
</div>
<!-- ... -->
</main> A simple <main>
<div>
<h1>
What is VitePress?
<a class="header-anchor" href="#what-is-vitepress" aria-label="Permalink to "What is VitePress?"">#</a>
</h1>
<!-- ... -->
<h2>
Use Cases
<a class="header-anchor" href="#use-cases" aria-label="Permalink to "Use Cases"">#</a>
</h2>
<!-- ... -->
</div>
<!-- ... -->
</main> However, the best semantics are provided by MDN. I totally understand if you don't want to introduce breaking changes, but still I'd like to ask, if this would be an option. I guess it is still easier at this point, instead of introducing breaking changes at a later stage (after alpha). I'm willing to provide PRs for all changes necessary (of course with some guidance by you). |
adfcfe4
to
7b941cd
Compare
You're suggestion was perfect! Yes, using With the way Docusaurus solved it, the screen reader only reads the heading without the mention of So this would be a perfectly accessible variant. I'll update this PR ASAP. However, I'd argue that the MDN variant is semantically better/richer. Maybe something to keep in mind for the future. |
…ace (HTML Entity) and custom renderAttrs
I've updated the PR with the proposed solution. It's not made using a custom renderer but with the variant "Link After Header", although a bit hacky. But it's the best solution I could come up with, still respecting all possible user configurations (i hope 🤞). |
There is one failing test LGTM once we fix the test! |
close #2039