Rating
Stars or bolts that flicker on as you hover, with half steps.
Built on Icons.
How was your order?
Flat white, oat · Halden Street Roasters
Installation
npx shadcn@latest add https://neonkit.heyaadi.com/r/rating.jsonUsage
import { Rating } from "@/components/ui/rating"
<Rating label="Your rating" defaultValue={4} />Examples
Half steps
With allowHalf, the left half of an icon picks the half value and the arrow keys move by 0.5.
Read-only average
Read-only ratings show fractional values exactly and are announced as an image.
Icons and colors
Sizes
API reference
Also accepts native div attributes, and the ref points at the icon row. className and style go to the icon row.
| Prop | Type | Default |
|---|---|---|
value | numberControlled value, from 0 (unrated) to max. | None |
defaultValue | numberInitial value when uncontrolled. | 0 |
onValueChange | (value: number) => voidCalled on click or key press. Clicking the current value sends 0. | None |
max | numberNumber of icons. | 5 |
allowHalf | booleanHalf values from the pointer and in 0.5 keyboard steps. | false |
icon | "star"The icon shape. | "star" |
readOnly | booleanDisplay only. Not focusable, announced as an image with the value. | false |
disabled | booleanDims the icons and ignores input. | false |
label | ReactNodeVisible label above the icons. Names the control. | None |
formatValue | (value: number, max: number) => stringText read to screen readers for the value. | "3.5 of 5" |
onHoverChange | (value: number | null) => voidThe previewed value while the pointer is over the icons, then null. | None |
name | stringSubmits the value with a surrounding form. | None |
color | NeonColorPalette name or hex. Falls back to --neon-accent, then cyan. | inherited |
size | "sm"Icon size: 16, 24 or 32px. | "md" |
containerClassName | stringClasses for the outer block when a label is set. | None |
Accessibility
- With name, a form reset puts back the starting rating.
- The icon row is a role="slider" with aria-valuetext such as "3.5 of 5", or "No rating" at 0.
- Right and Up raise the value, Left and Down lower it, Home clears and End sets the maximum. Number keys jump straight to a value.
- Without a visible label, pass aria-label.
- Newly lit icons flicker on in sequence. With reduced motion they switch on without the flicker.