-
-
Notifications
You must be signed in to change notification settings - Fork 437
Closed
Labels
Description
🚀 Feature Proposal
Just as titleProp allows the addition of a custom title via props, let's also make a custom desc (and its id) available as well! This will make it easier to build in accessibility into our svg components.
Motivation
I was looking at the w3 guidelines for svgs and it was recommended to have a title and description so that users can understand the meaning behind an svg.
Example
In code, something like:
Take this svg (taken from here):
<?xml version="1.0" encoding="UTF-8"?>
<svg
width="48px"
height="1px"
viewBox="0 0 48 1"
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
>
<!-- Generator: Sketch 46.2 (44496) - http://www.bohemiancoding.com/sketch -->
<title>Rectangle 5</title>
<desc>Created with Sketch.</desc>
<defs></defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g
id="19-Separator"
transform="translate(-129.000000, -156.000000)"
fill="#063855"
>
<g id="Controls/Settings" transform="translate(80.000000, 0.000000)">
<g id="Content" transform="translate(0.000000, 64.000000)">
<g id="Group" transform="translate(24.000000, 56.000000)">
<g id="Group-2">
<rect id="Rectangle-5" x="25" y="36" width="48" height="1"></rect>
</g>
</g>
</g>
</g>
</g>
</g>
</svg>
And do something like:
import * as React from 'react'
const SvgComponent = (props) => (
<svg width="1em" height="1em" viewBox="0 0 48 1" {...props}>
<desc id={props.descId}>{props.desc}</desc>
<path d="M0 0h48v1H0z" fill="currentColor" fillRule="evenodd" />
</svg>
)
export default SvgComponent
Pitch
Making SVGs accessible benefits everyone and this will make it a lot easier to create accessible svgs.
Reactions are currently unavailable