question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rating component is not accessible

See original GitHub issue

According to the WAVE tool (extension available at: https://addons.mozilla.org/en-US/firefox/addon/wave-accessibility-tool/), the Rating component is not accessible, i.e. it is not clear what each star represents.

Here is a sketch of patch to make it better:

diff --git a/src/ui/components/Rating/index.js b/src/ui/components/Rating/index.js
index 24e584192..e6364a81c 100644
--- a/src/ui/components/Rating/index.js
+++ b/src/ui/components/Rating/index.js
@@ -131,6 +131,9 @@ export class RatingBase extends React.Component<InternalProps, StateType> {
       if (hoveringOverStar !== null) {
         isSelected = thisRating <= hoveringOverStar;
       }
+
+      const title = this.renderTitle(rating, readOnly, thisRating);
+
       const props = {
         className: makeClassName('Rating-star', `Rating-rating-${thisRating}`, {
           'Rating-selected-star': isSelected,
@@ -140,7 +143,7 @@ export class RatingBase extends React.Component<InternalProps, StateType> {
         key: `rating-${thisRating}`,
         onClick: undefined,
         onMouseEnter: () => this.onHoverStar(thisRating),
-        title: this.renderTitle(rating, readOnly, thisRating),
+        title,
       };
 
       if (readOnly) {
@@ -151,9 +154,21 @@ export class RatingBase extends React.Component<InternalProps, StateType> {
         props.onClick = this.onSelectRating;
       }
 
+      const id = `Rating-rating-${thisRating}-title`;
+
       return (
         // eslint-disable-next-line react/jsx-key
-        <button type="button" value={thisRating} {...props} />
+        <React.Fragment>
+          <button
+            aria-describedby={id}
+            type="button"
+            value={thisRating}
+            {...props}
+          />
+          <span id={id} className="visually-hidden">
+            {title}
+          </span>
+        </React.Fragment>
       );
     });
   }

I believe this would be a very nice improvement.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shristitcommented, Oct 19, 2018

Hi @willdurand I would like to work on it , Can I?

0reactions
AlexandraMogacommented, Nov 20, 2018

Yes, the tool modifies other page contents as well, not only the ratings section.

In that case, I’m marking the issue as verified fixed on -dev.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react Rating component not working as expected
I stored my rating as a part of state and then set the initialRate to reflect that state. That made my ratings stick....
Read more >
5 star rating system - ACTUALLY accessible, no JS, no WAI ...
In this article I will explain how I built a star rating system that is ACTUALLY accessible, easy to style for your own...
Read more >
material-ui/lab/rating Rating component not working ... - GitHub
Rating component not working with custom icons Current Behavior On change is working but the rating is not changed Expected Behavior ...
Read more >
Rating | The Component Gallery
When displaying a non-interactive rating you should provide accessible text describing the rating. For example, by using an image with an ...
Read more >
React Rating component - Material UI - MUI
The read only rating is not focusable. API. See the documentation below for a complete reference to all of the props and classes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found