Rating
newA star rating with radio-group semantics and optional half values.
Use the arrow keys to change it.
Installation
npx shadcn@latest add @blank/ratingUsage
import { Rating, RatingItem } from "@/components/ui/rating"<Rating defaultValue={3} aria-label="Rating" />The group is one tab stop. Arrow keys change the value the way they move
through radio buttons, Home and End jump to the ends. Name the group with
aria-label or point aria-labelledby at a FieldLabel.
Stars follow brand, like every other selection. For gold stars pass
className="text-warning-primary". A star pops in as it fills, on hover too.
Examples
Half values
With step={0.5} the pointer picks the half of the star it is over and the
arrow keys move by halves. clearable lets a second click on the current value
reset it to zero.
3.5
Sizes and icons
RatingItem takes any icon. Style it off the item's data-state —
full, half or empty — through the group/rating-item group.
API Reference
Rating
| Prop | Type | Default |
|---|---|---|
value / defaultValue | number | 0 |
onValueChange | (value: number) => void | — |
max | number | 5 |
step | 0.5 | 1 | 1 |
clearable | boolean | false |
size | "sm" | "default" | "lg" | "default" |
disabled / readOnly / required | boolean | false |
name | string | — |
Without children, Rating renders max items.
RatingItem
| Prop | Type | Default |
|---|---|---|
index | number | mount order |
children | ReactNode | (state: "full" | "half" | "empty") => ReactNode | a star |