-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
fix(utils): make SVGO not remove title #6684
Conversation
By default, SVGR removes the `<title>` tag from SVG inputs. This hinders a11y since "the `<title>` element provides an accessible, short-text description of any SVG container element or graphics element". Modern browsers also show tooltips on hover for inline SVG with the `<title>` tag. See https://developer.mozilla.org/en-US/docs/Web/SVG/Element/title
✔️ [V2] 🔨 Explore the source changes: aa63e1c 🔍 Inspect the deploy log: https://app.netlify.com/sites/docusaurus-2/deploys/620b5512fb025d0008fd5ede 😎 Browse the preview: https://deploy-preview-6684--docusaurus-2.netlify.app |
⚡️ Lighthouse report for the changes in this PR:
Lighthouse ran on https://deploy-preview-6684--docusaurus-2.netlify.app/ |
removeTitle: false
to svg loaderThere 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.
Was wondering, last time I checked, aria-labelledby
is the one that helps with a11y, and title
is more of a supplement; I guess it's just because title
can be more ergonomically embeded in the SVG?
Hope this isn't an anti-pattern, but I have a use-case where I'm displaying an SVG icon without an element that labels it, so |
Yeah, I just checked, seems in SVG land |
Motivation
By default, SVGR removes the
<title>
tag from SVG inputs. This hinders a11y since "the<title>
element provides an accessible, short-text description of any SVG container element or graphics element."See: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/title
The
<title>
tag can be set via the SVG React component'stitle
prop, but it's unintuitive that existing<title>
tags from the SVG files themselves get stripped beforehand.This will not break behaviour for existing users since the
title
prop seems to override the image's default<title>
tag if set according to the SVGR API docs:See: https://react-svgr.com/docs/options/#title
Have you read the Contributing Guidelines on pull requests?
Yes
Test Plan
Updated the existing test at
packages/docusaurus-utils/src/__tests__/webpackUtils.test.ts
.Related PRs
N/A