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

a11y improvements #32

Closed
eelcoj opened this issue Dec 5, 2024 · 4 comments
Closed

a11y improvements #32

eelcoj opened this issue Dec 5, 2024 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@eelcoj
Copy link
Collaborator

eelcoj commented Dec 5, 2024

I am wondering if there are attributes that can be added by default that would improve a11y?

@eelcoj eelcoj added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Dec 5, 2024
@goulvench
Copy link

Hi! I can't provide code at the moment but here's a link to explain the various options for accessible icons: https://css-tricks.com/accessible-svg-icons/

TL;DR: it depends.

The long version:

  • if the image is decorative, use aria-hidden="true" to hide it from screen readers and you're done.
  • if the image provides useful information:
    • either give it a role="img" attribute and add a <title>#{title}</title> tag,
    • or add an aria-label="#{title}" to the parent element (link, button), and use aria-hidden="true" to hide the image.

The simplest implementation for the library would be to just add aria-hidden="true" by default, and explain that the icon needs to sit beside text or be nested inside a parent with aria-label="#{title}".

Another (slightly costlier) option would be to accept an alt parameter, and inject it as a title tag if it's present, or add the ARIA hidden attribute if it's empty or nil.

Additionally, adding a title attribute is usually helpful for icon-only links and buttons, because sometimes icon designs can be unclear, ambiguous, or simply fail to load. Because accessibility is not only about blind users but also visually impaired, and mental issues, and temporary conditions: headache, cracked screen...

@eelcoj
Copy link
Collaborator Author

eelcoj commented Dec 16, 2024

Thanks for the insights, @goulvench. Would like to move this forward some how.

It's tricky. There's nothing that can be added to Rails Icons to “make it work” (not sure if adding aria-hidden=true is the way to go but default?). It really depends on the situation?

Thinking of these changes as a starting point:

  • make aria a first-class attribute (similar to the data attribute);
  • extend docs to give best practices on this topic.

Any expert who wants to chime in too?

@goulvench
Copy link

The simplest solution would be to just add the aria attribute, add a warning in the documentation, and move on, because ultimately it's the developer's job to add text or an aria-label in the right place, which is outside the scope of this gem.

The title option is more cumbersome, as the icon may already have a title tag, which could need to be overwritten or left as is.

@eelcoj
Copy link
Collaborator Author

eelcoj commented Jan 30, 2025

Closing this per comments above. ☝ If you read this, feel free to add your comments or suggestions if you have any professional insights.

@eelcoj eelcoj closed this as completed Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants