lucide icon indicating copy to clipboard operation
lucide copied to clipboard

[Feature Request] Accessibility Improvement / Tooltip Support

Open veeru153 opened this issue 3 years ago • 6 comments

I shifted to Lucide from Feather after having no way to add tooltips directly. A similar issue (https://github.com/feathericons/react-feather/issues/67) exists for Feather which references this project but I didn't see any request or any implementation here yet. The gist of this issue/request is the ability to add alternative text like this:

<Icon alt="Navigate to Report" />

This would allow browsers to display a tooltip when you hover the cursor over the icon like this:

image

The linked issue goes into more detail. The icons work really well as buttons and this addition could improve the accessibility of the websites using these icons directly.

veeru153 avatar Jan 19 '22 03:01 veeru153

@veeru153 Thanks for opening. Is <Icon title="Delete" /> not working mentioned in that issue?

ericfennis avatar Jan 19 '22 13:01 ericfennis

Thank you for the quick response.

No this does not work. After some devtooling, the reason seems to be that when we add a title prop to the icon, it gets passed as an attribute to the SVG element like this:

<svg ... title="Delete">...</svg>

In order to render the tooltip, the text should be a Title element nested inside the SVG element like this:

<svg ...>
  <title>Delete</title>
  ...
</svg>

veeru153 avatar Jan 19 '22 16:01 veeru153

@veeru153 Allrighty I get it. Also read some more about it. It is also good to increase accessibility.

My proposal to accomplish this, is that we make it possible to pass children in icons. That creates also new possibilities to render something "over" the icon. This also keeps it really flexible and easy to implement.

Example title and description

<Icon>
  <title>My awesome text</title>
  <desc>More detailed description about the icon</desc>
</Icon>

Example rendering something over the icon, for example amount of items.

<ShoppingCart>
  <text>5</text>
</ShoppingCart>

ericfennis avatar Jan 20 '22 12:01 ericfennis

Ooh yes! While this is different from the traditional image alt attribute, this seems to be a better approach for the reasons you mentioned. I am assuming this would allow nesting icons inside icons too? Something like:

<Book>
  <Code />
</Book>

veeru153 avatar Jan 20 '22 12:01 veeru153

@veeru153 Yess correct!

ericfennis avatar Jan 20 '22 12:01 ericfennis

Wanted to release this feature, but with a final test it doesn't work as expected. I tested it wrong before, I tested it by using the browser inspector and changed the position of the title element below the children in the DOM. That worked for some reason, the tooltip showed when hovering. A bit stupid but lesson learned, always test on initial render. So @veeru153 you were right, <title> and <desc> need to be placed before the children to make it work.

Here a test environment: https://codesandbox.io/s/tooltip-does-not-work-5jjh2e?file=/App.svelte

TLDR: Current implementation doesn't work, we need to have a new solution.

ericfennis avatar Feb 20 '22 14:02 ericfennis

So there is currently no way to make the icons accessible to screen readers?

TheodorRene avatar Oct 25 '22 08:10 TheodorRene

So there is currently no way to make the icons accessible to screen readers?

It's actually possible by using the aria attributes. For example, you can use aria-label instead of alt or for decorative icons you can use aria-hidden. But I would still prefer to set the alt attribute.

tommy4st avatar Dec 09 '22 23:12 tommy4st

@tommy4st Can you share the aria-label solution you mentionned? I just came from reading this article and they don't seem to mention aria-label as an option. They mostly refer to title, desc, aria-labelledby, and role="image". I'm currious if you tested it with screen-readers?

@ericfennis I'm a bit confused about that statement:

So @veeru153 you were right,

and <desc> need to be placed before the children to make it work. </desc>

Currently if we pass a

child to an icon it gets added after the svg markup. This causes problem with screen-readers? <img src="https://user-images.githubusercontent.com/7883515/228891242-0922ffb1-5b57-47a0-884e-46e6417fed67.png" alt="image"> <p>I'm also having doubts about supporting this through children. I'm not finding a reason why </p><title> couldn't just be included in the svgs by default. I'm thing that if you're concerned about users wanting to overwrite it, a custom title prop could be added. Of course if there's not enough bandwith on your side currently, any workaround / intermediary solution would be much appreciated! <p>Thanks.</p>

eloiqs avatar Mar 30 '23 15:03 eloiqs