question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Navbar logos not exposing empty alt text

See original GitHub issue

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I’m using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

When an image is truly decorative (i.e., it doesn’t add additional context or information), we can apply alt="" (distinct from not supplying an alt attribute at all). This removes it from screenreader output, reducing clutter. This is especially pertinent for logos inside of links that also contain other link text, such as the typical navbar brand link. W3C’s Web Accessibility Initiative’s guidance on alt text for functional images includes an example just like this, where they recommend:

In this example, the W3C logo is used to supplement text within a link that leads to the W3C home page. The image does not represent different functionality or convey other information than that already provided in the link text, so a null (empty) value is applied, (alt=""), to avoid redundancy and repetition. In effect the image is a decorative adjunct or visual cue to the link text…

Prior work (#3352 and #3817) enabled Docusaurus users to provide empty strings for these alt properties in their configs. However, when they do so, the logos are provided alts anyways, populated with the site title. As a result, Docusaurus users are not able to meaningfully mark their logos as decorative to reduce screenreader clutter.

Reproducible demo

https://stackblitz.com/edit/github-rvbfnk?file=docusaurus.config.js

Steps to reproduce

  1. Navigate to repro on StackBlitz
  2. Check docusaurus.config.js, specifically the config for the navbar logo, which should have an alt: '' property.
  3. Inspect markup for navbar logo in the preview. Verify that the image has an alt attribute of "My Site", instead of the empty string.
  4. Navigate to navbar brand link with a screenreader. Verify that the link is announced as “My Site My Site,” because of the alt text duplication.

Expected behavior

If the user supplies an empty string for the logo’s alt (distinct from not providing an alt at all, or providing undefined or null), the logo should apply alt="", marking it as decorative for assistive technologies. Screenreaders won’t announce the logo, and navigating to the brand link should just announce the site title once.

Actual behavior

When the user supplies an empty string for the logo’s alt config, the alt attribute is being populated with the site title. This means that screenreader announcements are cluttered with redundant duplication.

Your environment

Latest versions as used on the StackBlitz playground. See repro on StackBlitz

Self-service

  • I’d be willing to fix this bug myself.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
BenDMyerscommented, Jun 22, 2022

More context in the discussions on #7659, but we ultimately decided to get a little more opinionated on logo alt text. The new flow is:

  1. Has the user supplied any logo alt text (including an empty string)? Use that.
  2. If not, has the user supplied a navbar title? If so, the logo complements the navbar title within the link, and so it’s decorative. Set the alt to the empty string.
  3. If no logo alt or visible navbar title have been provided, provide a fallback alt of the site title.
1reaction
Josh-Cenacommented, Jun 22, 2022
  1. If logo.alt is ""—we definitely want to obey that and render alt="".
  2. If logo.alt is undefined—we infer based on navbarTitle and title. If there’s navbarTitle, we use that (that’s the current behavior, but as we agreed in https://github.com/typescript-eslint/typescript-eslint/issues/5213, it leads to duplicate announcements, so we can rethink about it as well).
  3. If navbarTitle is falsy (so nothing gets rendered), we have to announce something for the link, so we use title instead.

So yes, logo.alt ?? (navbarTitle || title) is correct.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Image has non-empty accessible name | ACT Rule | WAI - W3C
This img element has an empty accessible name and an implicit role of img because it is missing an alt attribute. <img src="/test-assets/shared/w3c-logo.png"...
Read more >
When is it acceptable to leave the alt text empty on an HTML ...
In some cases, the alternate text cannot be known or is unnecessary, and in these cases, alt="" is inaccurate, because it implies that...
Read more >
Image not in the accessibility tree is decorative
This img element with an empty alt attribute which is not included in the accessibility tree is purely decorative. <p>Happy new year!
Read more >
Annoying website features I face as a blind person
The alt attribute is for an alternative to the image, not a description of the image. For decorative images, the alternative is the...
Read more >
Image Missing Alternative Text - Equalize Digital
To fix an Image Missing Alternative Text error, you will need to add an alt tag to the image with appropriate text describing...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found