Rating

PreviousNext

A star rating whose fill sweeps out from the pointer and whose committed star pops on the fast spring.

3
half steps
read only

Installation

pnpm dlx shadcn@latest add https://matos-ui.com/r/rating.json

Usage

import { Rating } from '@/components/matos-ui/rating'
const [value, setValue] = useState(3)

<Rating value={value} onValueChange={setValue} />

Examples

Half steps

<Rating defaultValue={3.5} allowHalf />

Read only

<Rating value={4} readOnly />

Inside a form

<form action={submit}>
  <Rating name="score" defaultValue={0} />
  <button type="submit">Send</button>
</form>

Accessibility

The control is a single role="slider" node. Arrow keys move by one step — half a star when allowHalf — and Home / End jump to the ends. Clicking the star the rating already rests on clears it back to 0.

Under prefers-reduced-motion the pop and the sweep are dropped; the fill still changes colour, it just doesn't scale or ripple.

Reference

Rating Props

PropTypeDefaultDescription
valuenumber-Controlled value (0–max).
defaultValuenumber0Initial value when uncontrolled.
onValueChange(value: number) => void-Fires with the committed rating; 0 when cleared.
maxnumber5Number of stars.
allowHalfbooleanfalseHalf-star precision on hover, click and keyboard.
readOnlybooleanfalseRender the stars without interaction.
disabledbooleanfalseDisable interaction and dim the control.
showValuebooleanfalsePrint the numeric value next to the stars.
namestring-Name for a hidden input, so the value posts in a form.
size"sm" | "md" | "lg""md"Star size preset.