Star rating
Lets users give a star rating, or shows an existing rating.
zb:rating zubazar/ui-pro
This component is in Zubazar UI Pro; Zubazar UI Pro brings Zubazar UI with it. Installing Zubazar UI Pro →
Basic usage
value is the starting rating, and label tells screen readers what the rating is about.
<zb:rating :value="3" label="Order satisfaction" />
| Prop | Values |
|---|---|
value | Initial rating (integer) |
label | Screen reader name; otherwise the page's aria-label, then "Rating" |
Read-only
readonly draws a display that cannot be clicked; with fractional ratings only whole stars are filled.
<div class="flex items-center gap-3">
<zb:rating :value="4" readonly />
<span class="text-sm text-dim">4.0 · 128 reviews</span>
</div>
| Prop | Values |
|---|---|
readonly | true | false |
Sizes
size picks the star size: sm in table rows, the default md, and lg in headings.
<div class="flex flex-wrap items-center gap-8">
<zb:rating :value="4" readonly size="sm" />
<zb:rating :value="4" readonly />
<zb:rating :value="4" readonly size="lg" />
</div>
| Prop | Values |
|---|---|
size | sm | md | lg |
In a form
With name, the selected rating is sent with the form in a hidden field; when no rating is selected (0), the field is sent empty.
<form method="POST" action="{{ route('orders.rate', $order) }}">
@csrf
<zb:rating name="rating" :value="old('rating', 0)" label="Order satisfaction" />
<zb:button type="submit" size="sm" class="mt-4">Submit</zb:button>
</form>
| Prop | Values |
|---|---|
name | Name of the form field |
With Livewire
wire:model writes the selected rating to the Livewire property (on every click with .live); the validation error shows below the stars automatically.
<zb:rating wire:model.live="rating" label="Order satisfaction" required hint="Your rating is not shown to the seller." />
| Prop | Values |
|---|---|
wire:model | Livewire property |
hint | Shown when there is no error |
Props
The values the component takes. What are props and slots?
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | 0 | Initial rating |
max | number | 5 | Number of stars |
readonly | boolean | false | Read-only display |
size | — | md | sm · md · lg |
label | — | null | Screen reader name. Otherwise the page's aria-label is used; without one, "Rating", in read-only mode "value / max". With aria-labelledby, no default name is written |
name | — | null | Field name for plain forms; the rating is sent in a hidden field (not in read-only mode) |
hint | — | null | Help text below the stars when there is no error; linked to the group of stars with aria-describedby (not in read-only mode) |
input-class | — | null | Classes of the group of stars itself; class places the whole field |
Advanced
With Alpine
x-model binds the selected rating to an Alpine variable; if the variable changes from outside, the stars update as well.
<div x-data="{ rating: 3 }" class="flex items-center gap-3">
<zb:rating x-model="rating" label="Order satisfaction" />
<span class="text-sm text-dim">Selected: <span x-text="rating"></span> / 5</span>
</div>
| Prop | Values |
|---|---|
x-model | Alpine variable |
Number of stars
max sets the number of stars shown; the default is 5.
<zb:rating :value="7" :max="10" readonly />
| Prop | Values |
|---|---|
max | Number of stars |
Developer notes
- The rating is also kept in a hidden field named after the property, and a
changeevent is dispatched on click, sozb:formdirty-checkandzb:form-actionssee the change. - Attributes such as
classandwire:keystay on the outer wrapper;required,aria-*anddata-*go to the star group, andautofocusto the first star.