Rating component is not accessible
See original GitHub issueAccording 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:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @willdurand I would like to work on it , Can I?
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.