Skip to content
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

Alt text / labels #42

Open
magikmw opened this issue Apr 18, 2024 · 5 comments
Open

Alt text / labels #42

magikmw opened this issue Apr 18, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@magikmw
Copy link

magikmw commented Apr 18, 2024

Hi, I'm trying to figure out a way to add an alt attribute to icons for accessibility.

So far I've wrapped the icon into a div and added a label there, but I think it would be great if this lib would provide a way to add a label directly.

I'd be willing to try and tackle this myself if pointed in the right direction.

@marc2332 marc2332 added the enhancement New feature or request label Apr 18, 2024
@marc2332
Copy link
Member

marc2332 commented Apr 18, 2024

That sounds like a cool idea! I'd do the following:

  1. Add a new trait method in the codegen crate (
    impl IconShape for {ICON_NAME} {
    ) where it returns a string with with the alt text, this alt text could be extracted perhaps from the icon name?
  2. Adapt the Icon component so the svg element has the title element filled with the value returned by calling icon.alt() (https://github.com/dioxus-community/dioxus-free-icons/blob/main/packages/lib/src/icon_component.rs)

@marc2332
Copy link
Member

Feel free to let me know if you have any issue/doubt! I can also take care of this if you want ✌️

@marc2332
Copy link
Member

As a temporal solution, you could just pass the alt text to the title attribute in your app btw!

@magikmw
Copy link
Author

magikmw commented Apr 19, 2024

Thanks for quick replies, I appreciate it.

That sounds like a cool idea! I'd do the following:

I'll take a look when I have a bit more time.
I did review docs in between your replies and found the title attribute which seems to be working just fine for the accessibility story.

I'll test bit further later on with a proper screen reader, but I think I might have been a bit too quick with creating an issue!

@marc2332
Copy link
Member

Even though title prop exists, we could still implement a default value for it, so you get accessibility out of the box!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants