Very good
Playground
Change the props and copy the code. The controls come from the component's TypeScript types.
Props
max5
size20
import { Rating } from "@/components/ui/rating";<Rating defaultValue={3} />Installation
$ pnpm dlx shadcn@latest add @synccn/ratingFirst time in this project? Connect synccn with one command.
Usage
import { Rating } from "@/components/ui/rating";<Rating defaultValue={4} />API reference
Generated from the component's TypeScript types, so it always matches the code.
PropTypeDescription
- value
numberControlled rating.
- defaultValue
numberDefault
0Initial rating when uncontrolled.
- onValueChange
(value: number) => voidCalled with the new rating (0 when cleared).
- max
numberDefault
5Number of stars.
- readOnly
booleanDefault
falseDisplay only.
- size
numberDefault
20Star size in pixels.
- className
stringExtra classes for the root element.
Dependencies
Read from the component's imports when the site builds. The CLI installs all of these for you.
npm packages
- clsx for cn()
- tailwind-merge for cn()
- lucide-react for Star
Keyboard
- →or↑Add a star
- ←or↓Remove a star
Accessibility
- Exposed as a radiogroup, one radio per star.
From the source
Read from this component's code when the site builds, so it can't drift.
- ARIA roles: radio, radiogroup
- ARIA attributes: aria-checked, aria-label
- Keys handled: ArrowUp, ArrowDown, ArrowLeft, ArrowRight
- Shows a visible focus ring for keyboard users
More inputs
ButtonSeven variants, four sizes and a built-in loading state.InputText field with optional leading icon and invalid state.TextareaMulti-line field that grows with its content and counts characters.CheckboxChecked, unchecked and indeterminate, with label and description.SwitchToggle with a springy thumb in three sizes.Radio GroupPick one option, shown as dots or as selectable cards.