Skip to content
Alea0.1

Forms

Rating

Stars to rate something, or to show a rating.

Ant Design: Rate

import { Rating } from '@alea/ui';

Examples

Rating

Hover previews; arrows change it.

How useful was this?

4 of 5

Read only and sizes

Showing a score.

Props

Rating props

Stars to rate something; arrows move, like radios (Ant's Rate).

PropTypeDefaultDescription
classNamestring-Extra class names for the root element.
defaultValuenumber0The rating to start with.
getValueLabel((n: number) => string)nWords for each value, read by screen readers ("1 star" by default).
isDisabledboolean-Disables every part of it.
isReadOnlyboolean-Shows the value without letting people change it.
labelReactNode-Name of the rating ("Rate this plugin").
maxnumber5Number of stars. Default 5.
onChange((value: number) => void)-Called with the new rating.
size"sm" | "md" | "lg"'md'sm, md (default) or lg.
valuenumber-The rating (controlled), 0 for none.

Accessibility

  • A radio group: each star is "n stars"; read-only ratings are an image with the value.

Keyboard

KeyDoes
Arrow keysChange the rating

Do and don't

Do

  • Show the count of ratings next to the stars.
  • Use allowHalf only for display, not for input.

Don't

  • Don't use stars for a yes/no question.
  • Don't make it required without saying so.
Tested with axe, keyboard and screen reader roles