Use it where people score something in a product: CSAT after a closed ticket, product reviews in a
marketplace back office, QA scores, NPS. The stars sit in a track and the fill is one primary
pill: hovering stretches it from the start of the track to under the star, the stars it covers are
its own clip (so each star turns light exactly where the leading edge reaches it, never before),
pressing charges the star, and on release the pill settles with the temperament's bounce, the chosen
star is kicked, the score rolls and the label crossfades. For a free numeric value use a slider;
for two or three named choices use a segmented control.
import { Rating } from "@/components/ui/rating"export function Csat() { const [value, setValue] = useState<number | null>(4) return <Rating aria-label="How was this resolution?" value={value} onValueChange={setValue} />}
value is null when nothing is rated. Three presets:
stars (default): the track with the icons, the rolling score ("4.0") and the label pill
("Good"). allowHalf lands the pill's leading edge on the star's centre; icon takes star,
heart, circle or a render function ({ filled }) => ReactNode; labels gives one label per
step (Terrible, Poor, Okay, Good, Excellent by default for five stars).
scale: a 0-10 rail for NPS. The fill stretches along the rail and ends in a ball carrying the
chosen number; endLabels captions both ends. Below 28 px per stop the numbers become dots and
the ball alone carries the number.
compact: 16 px icons without a track for table cells and review lists, read-only by default
(role="img"), with the average beside it. The fill is the clip of the filled icons and moves on
the calm spring.
Choosing the current value again clears it (allowClear, on by default). name adds a hidden
input for forms. readOnly shows a value that cannot change; disabled dims the whole control.
The control is a role="radiogroup" (named by aria-label or aria-labelledby) of real
button role="radio" elements with roving tabindex; each is named "3 of 5: Okay", the checked
one carries the half value when there is one ("3.5 of 5").
A polite live region announces each change ("Rated 4 of 5, Good"). The score and the label pill
are aria-hidden (the radios already say it); the fill, the icons and the ball are decorative.
Each star has a 32 px hit area (24 px for sm and interactive compact). The focus halo
(ring-[3px] ring-ring/50) sits on the focused star only, above the fill; ring is never used
for the fill.
Icons over the fill are primary-foreground, outside it foreground/70 (compact: filled
foreground/50), all at least 3:1 against card in light and dark (measured on the default
tokens, compact empty stars: 3.5:1 light, 4.9:1 dark).
Read-only compact renders role="img" with "Rating: 4.5 of 5".
The fill pill fades and glides to its new extent in the short fade time, with no stretch, no press
charge and no kick. The score's digits and the label crossfade. Every state (hovered, rated,
cleared) looks the same as with motion.
Only transform, width of one absolutely positioned pill and opacity animate; the lit copy of
the icons rides inside the pill, so no per-star colour changes run while the pill moves. Nothing
runs at rest and there are no loops. The scale rail measures its width once and on resize with a
ResizeObserver. Third-party cost: motion only.
Technical sheet
Motion
calm
260 ms · bounce 0
lively
400 ms · bounce 0.3
playful
540 ms · bounce 0.45
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 15.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, motion.
Dependencies
motion · peer
Triggers
hover, click, press, a value change
Reduced motion
The fill pill fades and glides to its new extent in the short fade time with no stretch, no press charge and no kick; the score and the label crossfade.
Keyboard
Tab
Focuses the checked star (or the first one with no rating)
ArrowRight / ArrowUp
Rates one step higher (half a star with allowHalf); the pill and focus follow
ArrowLeft / ArrowDown
Rates one step lower
Home / End
Rates the lowest or the highest step
Space / Enter
Chooses the focused star; on the current value it clears when allowClear is on
Backspace / Delete
Clears the rating when allowClear is on
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)