Skip to content

Rating Group

Rating

A star rating built on native <input type="radio"> stars — single-select with browser-provided roving tabindex, arrow keys and form participation.

<script>
import RatingGroup from "@invisible-ui/svelte/RatingGroup.svelte";
</script>

In Elements, the stars take their names from the locale catalog. Choosing a star sends a bubbling change event with the rating as a number in detail.value:

<ds-rating-group label="Rating" name="rating" value="4"></ds-rating-group>
PropTypeDefaultDescription
label *string—Accessible group name.
maxnumber5Number of stars.
valuenumber | nullnullCurrent rating.
disabledbooleanfalseDisable the group.
errorstring | undefinedundefinedError message, shown under the stars and announced. Every star points at it through aria-describedby. The app owns it: a form reset leaves it in place, so the app clears it.
namestring | undefinedundefinedForm field name — the rating is submitted under it.
onValueChange((value: number) => void) | undefinedundefinedCalled when the rating changes.
Stay rating

A non-empty error shows the message under the control with a hazard icon and announces it as an alert. Every star points at it through aria-describedby. Neither the stars nor the radio group takes aria-invalid. The message is plain text.

<RatingGroup label="Rating" bind:value error={value === null ? "Choose a rating." : ""} />

The app owns the message and clears it: a form reset leaves it in place. In Flutter, the validator’s message clears on form reset.

  • A labelled role="radiogroup" of native radio stars; the browser handles arrow-key move/select and form submission.
  • A non-empty error links every star to the message through aria-describedby.
<RatingGroup value={3} max={5} label="Rating" />

In React, onValueChange reports the rating as a number:

<RatingGroup label="Rating" value={rating} onValueChange={setRating} />

Themeable via --ds-rating-*.