Rating Group
A star rating built on native <input type="radio"> stars — single-select with
browser-provided roving tabindex, arrow keys and form participation.
Import
Section titled “Import”<script> import RatingGroup from "@invisible-ui/svelte/RatingGroup.svelte";</script><script setup> import { RatingGroup } from "@invisible-ui/vue";</script>import { RatingGroup } from "@invisible-ui/react";<script type="module"> import "@invisible-ui/elements/define";</script>
<ds-rating-group></ds-rating-group>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>| Prop | Type | Default | Description |
|---|---|---|---|
label * | string | — | Accessible group name. |
max | number | 5 | Number of stars. |
value | number | null | null | Current rating. |
disabled | boolean | false | Disable the group. |
error | string | undefined | undefined | Error 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. |
name | string | undefined | undefined | Form field name — the rating is submitted under it. |
onValueChange | ((value: number) => void) | undefined | undefined | Called when the rating changes. |
| Prop | Type | Default | Description |
|---|---|---|---|
label * | string | — | Accessible name for the rating group (required). |
max | number | 5 | Number of stars. |
modelValue | number | null | undefined | v-model value; takes precedence over value when bound. |
value | number | null | null | Selected rating (1..max), or null. |
disabled | boolean | false | |
name | string | undefined | Form field name; the rating is submitted under it. |
error | string | undefined | Error message. When non-empty it shows after the control as an alert and describes each star. The application owns it: a form reset leaves it in place, and the application clears it. |
onValueChange | (value: number) => void | undefined | Called whenever the rating changes. |
| Event | Payload |
|---|---|
update:modelValue | value: number | null |
| Prop | Type | Default | Description |
|---|---|---|---|
label * | string | — | Accessible name for the rating group (required). |
max | number | 5 | Number of stars. |
value | number | null | null | Selected rating (1..max), or null. |
disabled | boolean | false | |
error | string | — | An error message shown under the control as an alert. It describes the control. The app owns it: a form reset leaves it in place, so the app clears it. |
name | string | — | Form field name; the rating is submitted under it. |
onValueChange | (value: number) => void | — | Called whenever the rating changes. |
| Attribute | Reactive | Description |
|---|---|---|
label * | yes | the group's accessible name |
max | yes | the number of stars; 5 by default |
value | yes | the selected rating, 1 to max |
name | yes | generated when absent, so the stars still form one group |
disabled | yes | |
error | yes | a message under the stars; the page owns it, so a form reset leaves it in place |
Reactive attributes re-render the element when they change after the first render.
Properties: value (number or null).
Emits: bubbling change CustomEvent with detail.value, the rating as a number.
Error message
Section titled “Error message”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.
Accessibility
Section titled “Accessibility”- A labelled
role="radiogroup"of native radio stars; the browser handles arrow-key move/select and form submission. - A non-empty
errorlinks every star to the message througharia-describedby.
Example
Section titled “Example”<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-*.