-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
fix(theme): add accessible name for the heading hash-link #8562
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
Conversation
Anchor elements must have an accessible name - a programmatically determinable name that comes either from the text content inside, from `aria-label`, or `aria-labelledby`.
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site settings. |
⚡️ Lighthouse report for the deploy preview of this PR
|
| <Link | ||
| className="hash-link" | ||
| to={`#${id}`} | ||
| aria-labelledby={id} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be better to use children instead of id there?
(ie "Project Structure" instead of "project-structure")
Ids are not necessarily as human readable as the original text of the heading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aria-labelledby accepts the id of an element containing some text. And because the heading contains e.g. "Project structure" text, it becomes the accessible name of the link as well.
But if you are mentioning children, it would be even better to do this: aria-label={`Direct link to ${children}`}. I just was not sure about TypeScript here (not an expert). Will children always be only text content or it's possible there will be some tags too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm right it might not always be a string
| aria-labelledby={id} | ||
| title={translate({ | ||
| id: 'theme.common.headingLinkTitle', | ||
| message: 'Direct link to heading', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want to update this to Direct link to {headingTitle}?
I think this was what we wanted in the original issue? (this would require modifying all our translation files to add the extra param/placeholder)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can, and I think it would be great if we could do this:
<Link
aria-label={`Direct link to ${headingTitle}`} // to set the accessible name
title={`Direct link to ${headingTitle}`} // this will be shown to users who hover over the link
/>(just with that translation syntax)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 let me edit the PR I'll do this
slorber
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did my best to update all the locales
It's likely that there are some mistakes. I'll merge the pr asap so if there are mistakes open a new PR to fix issues.
| "theme.colorToggle.ariaLabel.mode.light": "浅色模式", | ||
| "theme.common.editThisPage": "编辑此页", | ||
| "theme.common.headingLinkTitle": "标题的直接链接", | ||
| "theme.common.headingLinkTitle": "标题的直接 {heading}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have no idea if I should add a space or not 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "theme.common.headingLinkTitle": "标题的直接 {heading}", | |
| "theme.common.headingLinkTitle": "{heading}的直接链接", |
Whether to add a space or not is a hard question. Since we should be able to insert Chinese text here, I suggest no—but if heading is always Latin, then my own preference is yes.
packages/docusaurus-theme-translations/locales/zh-Hant/theme-common.json
Show resolved
Hide resolved
I can confirm the Czech locale is fine :) |
|
@slorber Looks like #8562 (comment) is missed. I won't be able to get to my computer until a couple of hours later, so it would be great if you can fix that earlier in case I forget. |
What do you mean by it's missed? I'd prefer if you fix it because it's hard for me to figure out what is the right final solution 😅 |
|
Oops, I didn't see the suggestion was already applied. |
Pre-flight checklist
Motivation
An accessibility improvement - anchor elements must have an accessible name - a programmatically determinable name that comes either from the text content inside, from
aria-label, oraria-labelledby.There is no reliable way to hide the textual contents of pseudoelements from screen readers, would be better to implement the link text as
<span aria-hidden="true">#</span>but not sure if that would be wanted.Test Plan
Before - the accessible name of the link is not meaningful:
After - the accessible name of the link is meaningful and unique:
Test links
Deploy preview: https://deploy-preview-8562--docusaurus-2.netlify.app/docs/installation/#requirements
Related issues/PRs
#8336