Forms
Rating
Stars to give a rating, or to show one: a review form, a satisfaction survey, the score of an item in a list.
Nothing to show
"Your rating" over five empty stars. Moving the pointer over them fills the stars up to the one under it; clicking the third sets $score to 3 and leaves three stars filled in yellow.
Showing a rating #
Only the stars, with no field: 4.5 shows four full stars and a half one. Screen readers read "4.5 of 5".
Nothing to show
Clearable, with other icons #
Three hearts. With clearable, clicking the checked heart again clears the rating and sets $love to null.
Nothing to show
Sizes #
size scales the stars, which take the size above the one given.
Nothing to show
Customization #
star: reaches each star's label.
Nothing to show
Reference
Rating
| Prop | Type | Default | Description |
|---|---|---|---|
value |
int | float | null |
The rating. With readonly it may have a half (3.5); in the field it checks the star with that value. |
max |
int | 5 |
The number of stars. |
readonly |
bool | false |
Shows the rating as stars, with no field and no interaction. |
clearable |
bool | false |
Clicking the checked star clears the rating. |
label |
string | slot | null |
The title of the group, translated. |
description |
string | slot | null |
Text under the title. |
icon |
string | mdi:star |
The filled star. |
iconHalf |
string | mdi:star-half-full |
The half star, with readonly. |
iconEmpty |
string | mdi:star-outline |
The empty star. |
color |
string | yellow |
A color name for the filled stars, in its bright shade (400). |
size |
string | md |
xs, sm, md, lg, xl, 2xl or 3xl. The stars are one size above it. |
wire:model and x-model bind the rating, or null once cleared; name sends it with a form. Livewire casts it by the property's type (3 for an int); x-model gets the radio's text ('3') unless written x-model.number. required goes on every star, so a form can't be sent without a rating.
tk:rating
Prefixes
| Prefix | Goes to |
|---|---|
star: |
Each star's <label>. |
error: |
The validation error. |
Customization
Classes go to the <fieldset> (to the <span> with readonly). The parts take prefixes (listed in the Reference above).
Nothing to show
Accessibility
It follows the WAI-ARIA radio group pattern with native radios: a <fieldset> named by its label, and one radio per star, named "1 of 5", "2 of 5"... The focus ring shows around the star that has the focus. With readonly, the stars are a single role="img" named "4.5 of 5".
| Key | Action |
|---|---|
| Tab | Moves the focus into the group, to the checked star or the first one. |
| Arrow Right / Arrow Down | Checks the next star. |
| Arrow Left / Arrow Up | Checks the previous star. |
| Space | Checks the star that has the focus. |
Behavior notes
- A cleared rating sends
nullto the binding. A Livewire property declared with another default (public ?int $score = 2) goes back to that default on the next request: declare it aspublic ?int $score = nulland set the starting value inmount(). - Inside a readonly form the stars are locked and keep their colors.