Feature Request: Accessibility improvement / tooltip support
I have been using react-feather for a lot of my internal administration apps over the last year or so. It's very straight forward to work with and works well on all the devices that I develop for. Lately, we have been doing an accessibility audit on some of the applications and one of the things came up is the fact that when icons are used as "buttons" they are missing "alt text" / helpful info on what will happen.
I have been reading up on what seems to be the common way to achieve this with the inline SVGs as those react-feather produces. The most common option seems to be using a
I'd also be a big supporter of this!
An option would also be to allow passing children props to icons, enabling one to pass both <title> and <desc>.
Is it possible to confirm if support for title / desc / aria-labelledby is planned? We have started using react-feather-icons but as a11y is a hard requirement for us; without this we may have to explore other accessible versions instead. Be grateful for any info / guidance on this
I believe attributes such as aria-labelledby, title etc already work, as additional props just get passed to the SVG element:
import { Trash } from "react-feather";
const Component = () => {
return (
<Trash title="Delete" />
);
};
Additional child elements don't, however.
I'm using TS in my project, trying the above gives: Type '{ title: string; }' is not assignable to type 'IntrinsicAttributes & IconProps & { children?: ReactNode; }'. Property 'title' does not exist on type 'IntrinsicAttributes & IconProps & { children?: ReactNode; }'.ts(2322)
That might be a problem indeed.
The list of allowed attributes and types can be found here:
https://github.com/feathericons/react-feather/blob/c9698fa53e4bd577cdeffce18b054b97a3d765fc/src/index.d.ts#L4-L7
and here:
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/1349b640d4d07f40aa7c1c6931f18e3fbf667f3a/types/react/index.d.ts#L2341-L2607
Unfortunately, this library doesn't seem to be actively maintained, so if you want a response you might try the fork, Lucide Icons
I dug into the above types some more. The type of IconProps extends SVGAttributes<SVGElement> and SVGAttributes in turn extends AriaAttributes. Therefore can use aria-label instead. I'm hoping this will suffice in the meantime but not totally sure of the impact of using aria-label in this way instead of title / desc
Another way I added a tooltip to those icons is by wrapping them in a <span title="tooltip-text"><Icon /></span>.