Rating

Accessible React star rating that works as an input or a read-only display, with half-star precision, sizes, brand tone, and full keyboard support.

Rating collects or displays a star score. Use readOnly for display, allowHalf for half stars, and tone="brand" for SA green.

When to use

Use Rating to collect satisfaction after a service is delivered, or to display an average score. Set readOnly for display and allowHalf when averages need finer precision. Keep the scale at five stars; users know it.

For a question with labelled options, such as "How easy was this?", a RadioGroup gives clearer answers.

Examples

Rate a service

Half-star precision

Read-only average

Sizes

Props

Props declared by Rating. Native attributes of the underlying element pass through.

PropTypeDefaultDescription
size"sm" | "md" | "lg"
valuenumberControlled value (0…max). .5 increments are allowed when allowHalf.
defaultValuenumberUncontrolled initial value. Defaults to 0.
onValueChange(value: number) => voidFires with the chosen rating.
maxnumberNumber of stars. Defaults to 5.
allowHalfbooleanAllow half-star (.5) precision.
readOnlybooleanDisplay only - no interaction, exposed as role="img".
disabledbooleanNon-interactive and dimmed.
labelreact.ReactNodeVisible field label.
helperTextreact.ReactNodeHint shown below the field. Hidden while an error message is showing.
errorMessagereact.ReactNodeMessage shown below the field when error is true.
errorbooleanMarks the field invalid: sets aria-invalid and error styling.
tone"default" | "brand"SDGA Style axis. default (gold) · brand (SA green). Recolor per instance via the --ddga-rating-color CSS variable.
iconreact.ReactNodeSymbol rendered instead of the default star (e.g. a heart). Used for both the empty and filled layers - fill/empty colors come from CSS, so pass an icon that uses currentColor. Defaults to the SDGA star.
formatValueText(value: number, max: number) => stringBuilds the accessible value text / read-only label. Defaults to "{value} out of {max} stars". Override for localization.
idstring
classNamestring
aria-labelstringDefines a string value that labels the current element.
aria-labelledbystringIdentifies the element (or elements) that labels the current element.

Accessibility

The interactive Rating is a slider role: arrow keys change the score, Home and End jump to the extremes, and aria-valuetext announces the value with its label. A read-only Rating renders as an image with an accessible name, so it is announced but not focusable.

Label the control through label or aria-label, and use the error message to explain a missing rating.