Rating

Star rating radiogroup with hover preview fill, a staggered spring bounce on pick, optional half-star precision from the pointer position, click-to-clear, arrow/Home/End keyboard control, custom icons and a read-only display mode; controlled/uncontrolled, reduced-motion safe.

Preview

Rating preview width

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @karaui/rating
@karaui not found? Add it to components.json
{
  "registries": {
    "@karaui": "https://karaui.kamisama-v0.my.id/r/{name}.json"
  }
}

@karaui is in shadcn's public registry directory, so the latest CLI needs no setup. On an older CLI, merge this into the existing file once and every @karaui/… install resolves.

API Reference

value?
number

Controlled rating. 0 means unrated.

—
defaultValue?
number

Uncontrolled initial rating. Default 0.

0
onChange?
((value: number) => void)
—
max?
number

Number of icons. Default 5.

5
precision?
1 | 0.5

1 for whole icons, 0.5 for halves (picked by pointer x within the icon).

1
readOnly?
boolean

Display only: no hover, click or keyboard.

false
disabled?
boolean
false
clearable?
boolean

Clicking the current value clears it to 0. Default true.

true
icon?
ReactNode

Custom icon, rendered for both the empty and filled layer. Defaults to a star.

—
size?
number

Icon box size in px. Default 24.

24
aria-label?
string

Accessible name for the group. Default "Rating".

Rating
getLabel?
((value: number, max: number) => string)

Builds each option's accessible label.

(value: number, max: number) => `${value} ${value === 1 ? "star" : "stars"} out of ${max}`
className?
string
—
filledClassName?
string

Classes for the filled layer — set the fill color here.

—
emptyClassName?
string

Classes for the empty layer.

—

Updated