Star Rating
betaFive stars with a "3.0 · Good" caption whose lit stars pop in a staggered cascade when a rating is chosen.
- Forms
- 1 file
- 2 npm packages
- Accessibility notes
Loading the example…
pnpm dlx @dowel-ui/cli add star-ratingnpm packages installed: class-variance-authority, radix-ui.
import { StarRating } from "@/components/ui/star-rating";Default
Demo
Custom Labels
Sizes
<StarRating>
| Prop | Type | Default |
|---|---|---|
accentColour of the lit stars. Defaults to the foreground. | string | — |
defaultValueInitial rating when uncontrolled. | number | 0 |
disabled | boolean | — |
labelThe group's accessible name. | string | "Rating" |
labelsOne word per star, lowest first. Its length sets how many stars there are. | string[] | DEFAULT_LABELS |
name | string | — |
onValueChange | (value: number) => void | — |
placeholderCaption when nothing is chosen. | string | "No rating" |
required | boolean | — |
showCaptionShow "3.0 · Good" under the stars. | boolean | true |
size | "sm" | "md" | "lg" | "md" |
valueControlled rating, 0 for none. | number | — |
Plus every attribute of <div> except defaultValue, dir, onChange, children, value.
A Radix radio group named "Rating" (or aria-label): one tab stop, arrow keys move and select (mirrored in right-to-left layouts), and each star is a radio named "3 stars, Good" with a visible focus ring. The caption repeats the checked radio's name, so it is aria-hidden. Stars past the value dim rather than disappear, and the caption carries the rating in words, so colour is not the only signal. The pop cascade never plays on first paint and collapses to an instant change under reduced motion.
8/8
checks passed
- Tested — passes
- axe assertion — passes
- Keyboard tested — does not apply
- Storybook examples — passes
- Accessibility documented — passes
- Semantic tokens only — passes
- Motion from tokens — passes
- className merged — passes
- Visible focus — does not apply
- No fixed widths — passes