Skip to content

Conversation

@zmrhaljiri
Copy link
Contributor

@zmrhaljiri zmrhaljiri commented Jan 19, 2023

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, or aria-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">&#35;</span> but not sure if that would be wanted.

Test Plan

Before - the accessible name of the link is not meaningful:

before

After - the accessible name of the link is meaningful and unique:

after

Test links

Deploy preview: https://deploy-preview-8562--docusaurus-2.netlify.app/docs/installation/#requirements

Related issues/PRs

#8336

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`.
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jan 19, 2023
@netlify
Copy link

netlify bot commented Jan 19, 2023

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 55d0f50
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/63cb068ebaa59c0008c1232f
😎 Deploy Preview https://deploy-preview-8562--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

github-actions bot commented Jan 19, 2023

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟠 84 🟢 97 🟢 92 🟢 100 🟢 90 Report
/docs/installation 🟠 79 🟢 100 🟢 100 🟢 100 🟢 90 Report

<Link
className="hash-link"
to={`#${id}`}
aria-labelledby={id}
Copy link
Collaborator

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

Copy link
Contributor Author

@zmrhaljiri zmrhaljiri Jan 19, 2023

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?

Copy link
Collaborator

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',
Copy link
Collaborator

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)

Copy link
Contributor Author

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)

Copy link
Collaborator

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

Copy link
Collaborator

@slorber slorber left a 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}",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Josh-Cena ?

Have no idea if I should add a space or not 🤷‍♂️

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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.

@slorber slorber added pr: bug fix This PR fixes a bug in a past release. to backport This PR is planned to be backported to a stable version of Docusaurus labels Jan 20, 2023
@slorber slorber changed the title fix: Add accessible name for the hash-link fix(theme): Add accessible name for the heading hash-link Jan 20, 2023
@slorber slorber added the domain: a11y Related to accessibility concerns of the default theme label Jan 20, 2023
@zmrhaljiri
Copy link
Contributor Author

Did my best to update all the locales

I can confirm the Czech locale is fine :)

@Josh-Cena Josh-Cena changed the title fix(theme): Add accessible name for the heading hash-link fix(theme): add accessible name for the heading hash-link Jan 20, 2023
@slorber slorber merged commit d8459e5 into facebook:main Jan 26, 2023
@Josh-Cena
Copy link
Collaborator

@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.

@zmrhaljiri zmrhaljiri deleted the patch-1 branch January 26, 2023 22:09
@slorber slorber added backported This PR has been backported to a stable version of Docusaurus and removed to backport This PR is planned to be backported to a stable version of Docusaurus labels Jan 27, 2023
@slorber
Copy link
Collaborator

slorber commented Feb 1, 2023

@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 😅

@Josh-Cena
Copy link
Collaborator

Oops, I didn't see the suggestion was already applied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backported This PR has been backported to a stable version of Docusaurus CLA Signed Signed Facebook CLA domain: a11y Related to accessibility concerns of the default theme pr: bug fix This PR fixes a bug in a past release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inaccessible markdown heading links

4 participants