Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Star rating component - What are the correct accessibility and semantics to be used

I have a star rating component that currently has the following semantic. The SVG are just stars.

<div role='img' aria-label="6 out of 6 ratings">
  <svg role="presentation"></svg>
  <svg role="presentation"></svg>
  <svg role="presentation"></svg>
  <svg role="presentation"></svg>
  <svg role="presentation"></svg>
  <svg role="presentation"></svg>
</div>

I have used the role='img' aria role as I want to ideal treat this image as one image. I have then used the role='presentation' aria role on the SVG as I think the SVG's alone provide no extra information so want to remove the semantic meaning to the SVG and it's children. I read about the presentation role here.

I read a article on SVG accessibility and they go with slightly difference approach. The example they give is the following:

<body>
...
<svg xmlns=http://www.w3.org/2000/svg role="img" aria-labelledby="title  desc">
   <title id="title">Circle</title>
   <desc id="desc">Large red circle with a black border</desc>
   <circle role="presentation" cy="60" r="55" stroke="black" stroke-width="2" 
   fill="red" />
</svg>
…
</body>
  • They use role='img on the svg. I believe this does not apply to my situation and would be better for me to keep role='presentation' on my SVG?
  • They use title and desc. I believe that as a single star SVG it would not provide any extra benefit to the user? Also hovering over the SVG would reveal the title (and desc?) which I do not want.

Coming back to my example of how I currently have it:

  1. Is there anything I can do to improve the accessibility/ semantic design to make it more user friendly?
  2. Have I correctly used the right aria role for the container and the SVG?
  3. Should I be able to tab through my rating image (as a whole) as for the aria-label to be read out?
  4. Are there any other aria attributes I should be using?

Looking at the example on semantic-ui, they have no aria roles from what I can see.

like image 765
Corbuk Avatar asked May 03 '19 08:05

Corbuk


Video Answer


1 Answers

The MDN Web docs for img role has a link to a star rating role="img" example

They use aria-hidden instead of role="presentation"

According to the specs, the img role should already make its children presentational

I would add that being accessible implies more than just being accessible for screenreaders. For instance "3 blacks stars, 2 white stars" in the MDN example is something people may not understand (eg. people naturally reading from right-to-left).

"Grandma: Honey, Is it better to have 5 white stars, or 5 black stars?"

I would say that adding "Note: 3/5" next to the ratings, might be a good help.

like image 58
Adam Avatar answered Oct 10 '22 20:10

Adam