Rating
Star ratings you can click, hover and drive with the keyboard. Half steps, read-only display and custom icons.
How was the 2.4 release?
Installation
pnpm dlx nachui add ratingAnatomy
The interactive rating is a
radiogroup with one radio per step, so assistive tech reads it as a choice between values. Focus lands on the current value, the arrow keys move by one step, Home and End jump to the ends, and Backspace clears. Hovering previews a value without committing it.Variants
Default
Controlled with
value and onValueChange, or uncontrolled with defaultValue.How was the 2.4 release?
Half steps
precision={0.5} splits each star. The half is picked from where the pointer is. allowClear resets to zero when the current value is clicked again.Read only
readOnly renders an img with a label such as 4.6 of 5 and no buttons. Children render after the stars, for counts and averages.Northwind Desk Mat
4.6 (1284)
Mechanical Keyboard, 65%
4.2 (312)
Monitor Arm
3.8 (97)
Sizes
Custom icon
icon and filledIcon swap the shape. Recolor the fill through the rating-fill slot.API Reference
Rating
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | - | Controlled value |
defaultValue | number | 0 | Initial value when uncontrolled |
onValueChange | (value: number) => void | - | Called with the new value |
max | number | 5 | Number of steps |
precision | 1 | 0.5 | 1 | Whole or half steps |
size | "sm" | "default" | "lg" | "default" | Icon size |
readOnly | boolean | false | Display only |
disabled | boolean | false | Dims and blocks interaction |
allowClear | boolean | false | Picking the current value clears it |
name | string | - | Renders a hidden input for form submissions |
icon | ReactNode | star outline | Outline icon |
filledIcon | ReactNode | filled star | Icon drawn over the outline, clipped to the fill |
getLabel | (value: number, max: number) => string | "3 of 5" | Accessible label for each step and the group |
className | string | - | Additional CSS classes |
Found something to improve?
Notice a bug, typo, or missing detail on this page? Help us make the documentation better by opening a GitHub issue.