Skip to content

IconExternalLink, give aria-label "opens in new tab" #11331

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

WestonThayer
Copy link

@WestonThayer WestonThayer commented Jul 16, 2025

Pre-flight checklist

  • I have read the Contributing Guidelines on pull requests.
  • If this is a code change: I have written unit tests and/or added dogfooding pages to fully verify the new behavior.
  • [ ] If this is a new API or substantial change: the PR has an accompanying issue (closes #0000) and the maintainers have approved on my working plan.

Motivation

Test Plan

Before/after behavior with NVDA:

assistivlabs_win-nvda_2025.1.1_win-chrome_137_2025-07-16T17-55-57.258Z.mp4

Test links

Deploy preview: https://deploy-preview-11331--docusaurus-2.netlify.app/

@meta-cla meta-cla bot added the CLA Signed Signed Facebook CLA label Jul 16, 2025
Copy link

netlify bot commented Jul 16, 2025

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit b7c1176
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6877e6769050000009093e21
😎 Deploy Preview https://deploy-preview-11331--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 project configuration.

Copy link

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO Report
/ 🔴 34 🟢 98 🟢 100 🟢 100 Report
/docs/installation 🟠 57 🟢 97 🟢 100 🟢 100 Report
/docs/category/getting-started 🟠 68 🟢 100 🟢 100 🟠 86 Report
/blog 🟠 58 🟢 96 🟢 100 🟠 86 Report
/blog/preparing-your-site-for-docusaurus-v3 🟠 56 🟢 92 🟢 100 🟢 100 Report
/blog/tags/release 🟠 58 🟢 96 🟢 100 🟠 86 Report
/blog/tags 🟠 67 🟢 100 🟢 100 🟠 86 Report

@WestonThayer
Copy link
Author

WestonThayer commented Jul 16, 2025

Here's a (untested) patch with an alternate approach if desired. It doesn't seem bad to me that NVDA announces that there's visually a "graphic" there, but a <span className="screen-reader-only"> approach below would avoid that (and is more friendly to auto translate https://adrianroselli.com/2019/11/aria-label-does-not-translate.html).

diff --git a/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Link/index.tsx b/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Link/index.tsx
index a39b85a..9ce4c77 100644
--- a/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Link/index.tsx
+++ b/packages/docusaurus-theme-classic/src/theme/DocSidebarItem/Link/index.tsx
@@ -52,7 +52,12 @@ export default function DocSidebarItemLink({
         })}
         {...props}>
         {label}
-        {!isInternalLink && <IconExternalLink />}
+        {!isInternalLink && (
+          <>
+            <span className="screen-reader-only"> (opens in new tab)</span>
+            <IconExternalLink />
+          </>
+        )}
       </Link>
     </li>
   );
diff --git a/packages/docusaurus-theme-classic/src/theme/Footer/LinkItem/index.tsx b/packages/docusaurus-theme-classic/src/theme/Footer/LinkItem/index.tsx
index ac4f6b4..92b5fbc 100644
--- a/packages/docusaurus-theme-classic/src/theme/Footer/LinkItem/index.tsx
+++ b/packages/docusaurus-theme-classic/src/theme/Footer/LinkItem/index.tsx
@@ -30,7 +30,12 @@ export default function FooterLinkItem({item}: Props): ReactNode {
           })}
       {...props}>
       {label}
-      {href && !isInternalUrl(href) && <IconExternalLink />}
+      {href && !isInternalUrl(href) && (
+        <>
+          <span className="screen-reader-only"> (opens in new tab)</span>
+          <IconExternalLink />
+        </>
+      )}
     </Link>
   );
 }
diff --git a/packages/docusaurus-theme-classic/src/theme/Icon/ExternalLink/index.tsx b/packages/docusaurus-theme-classic/src/theme/Icon/ExternalLink/index.tsx
index 7b104df..87523b6 100644
--- a/packages/docusaurus-theme-classic/src/theme/Icon/ExternalLink/index.tsx
+++ b/packages/docusaurus-theme-classic/src/theme/Icon/ExternalLink/index.tsx
@@ -22,7 +22,7 @@ export default function IconExternalLink({
     <svg
       width={width}
       height={height}
-      aria-label="(opens in new tab)"
+      aria-hidden="true"
       className={styles.iconExternalLink}>
       <use href={svgSprite} />
     </svg>
diff --git a/packages/docusaurus-theme-classic/src/theme/NavbarItem/NavbarNavLink.tsx b/packages/docusaurus-theme-classic/src/theme/NavbarItem/NavbarNavLink.tsx
index 52e198d..016893b 100644
--- a/packages/docusaurus-theme-classic/src/theme/NavbarItem/NavbarNavLink.tsx
+++ b/packages/docusaurus-theme-classic/src/theme/NavbarItem/NavbarNavLink.tsx
@@ -39,9 +39,12 @@ export default function NavbarNavLink({
           <>
             {label}
             {isExternalLink && (
-              <IconExternalLink
-                {...(isDropdownLink && {width: 12, height: 12})}
-              />
+              <>
+                <span className="screen-reader-only"> (opens in new tab)</span>
+                <IconExternalLink
+                  {...(isDropdownLink && {width: 12, height: 12})}
+                />
+              </>
             )}
           </>
         ),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Links that open in new tabs/windows should be tagged for assistive technology
1 participant