Rating

Pick or show a score with stars or any other icon. The value only changes when the user clicks or uses the arrow keys, and hovering shows a preview.

Default

Control it with value and onChange, or start it with initialValue.

Types

Pass the property type to change the color.

Variants

outline shows only the border of the empty icons, filled fills them with a soft color.

Precision

With precision={0.5} each icon can be picked by its half.

States

readOnly shows a score without picking, disabled blocks it, and clearable lets a second click on the same value clear it.

Custom Amount

Customize the amount of icons with count.

Icon

Use icon for the filled state and emptyIcon for the empty one. With highlightSelectedOnly only the picked icon is lit, good for faces or emojis.

APIs

Rating.Props

AttributeDescriptionTypeAccepted valuesDefault
valuecurrent score, to control the componentnumber0 to count-
initialValuescore at the startnumber0 to count0
onChangecalled with the score the user picked(value: number) => void--
onHoverChangecalled with the previewed score, or null on leave(value: number | null) => void--
countamount of iconsnumber-5
precisionstep of the scoreRatingPrecision1, 0.51
typecolor of the iconsRatingTypesRatingTypesdefault
variantlook of the empty iconsRatingVariants'outline', 'filled'outline
iconicon of the filled stateReact.ReactNode-star
emptyIconicon of the empty stateReact.ReactNode-icon
readOnlyshow the score without pickingboolean-false
disabledblock the componentboolean-false
clearablea click on the current score clears itboolean-false
highlightSelectedOnlylight only the icon of the scoreboolean-false
getLabelaccessible name of each score(value: number, count: number) => string-3 of 5
...native propsHTMLAttributes--

RatingTypes

type RatingTypes =
  'default' | 'primary' | 'secondary' | 'success' | 'warning' | 'error' | 'info'

Accessibility

The component is a group of native radio buttons, so the arrow keys move the score and Tab leaves the group. Give it an aria-label. With readOnly or disabled it becomes an image named by getLabel.

Edit this page on GitHub