Skip to Content
zjkm-ui
Components

Star Rating

Rate from one to five stars.

Your rating
Props
<StarRating legend="Your rating" />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/star-rating.json
import { StarRating } from "@/components/star-rating"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

Rate from one to five stars. Hovering previews the rating. The stars are native radios named "1 star" to "5 stars", so arrow keys work and screen readers say the rating.

import { StarRating } from "@/components/star-rating";

export function Review() {
  return <StarRating legend="Your rating" name="rating" onChange={(n) => console.log(n)} />;
}

Props

PropTypeDefaultDescription
legendstringNames the group.
maxnumber5Number of stars.
namestringForm field name.
defaultValuenumber0Starting rating. 0 is none.
onChange(value: number) => voidCalled when the rating changes.
colorstring"#f59e0b"Lit star colour.
classNamestringClasses for the wrapper.

With reduced motion, stars don't grow on hover.

On this page