icons icon indicating copy to clipboard operation
icons copied to clipboard

Accessibility support

Open adamayres opened this issue 7 months ago • 0 comments

Thanks for the lib. I noticed that there is currently no way to add a title or desc element to the rendered svg which is useful for properly supporting accessibility, similar to this request for react-icons.

One option would be to expose the props title and desc on IconProps, something like:

export type IconProps = QwikIntrinsicElements["svg"] & { title?: string; desc?: string };
<SomeIcon title="Some title" desc="Some title" />

Then ensure they're removed from the {...props} before they're spread onto the svg.

Another option might be to allow for named slots, something like:

<SomeIcon>
  <title q:slot="title">Some title</title>
  <desc q:slot="desc">Some desc</desc>
</SomeIcon>

The problem here is that it's more difficult to enforce that the title and desc elements are used for their corresponding named slots, but maybe thats ok.

Seems like in either case it would require a change to the code that generates each icon here:

https://github.com/qwikest/icons/blob/599bb6ce0b2a560ad19d4ea92bb41f8a44d756db/generate/generate-icons.ts#L93-L103

I am open to creating a PR with the change, please let me know if there is a preference on an approach.

Related links:

https://css-tricks.com/accessible-svgs/ https://www.w3.org/TR/SVG11/struct.html#DescriptionAndTitleElements https://www.a11y-collective.com/blog/icon-usability-and-accessibility/

adamayres avatar Jul 07 '24 05:07 adamayres