Default
Hover to preview, click to choose. It is a radio group: Tab lands on the chosen glyph, then arrow keys, Home and End change the value.
Stars, hearts or suns somebody drew, where you pick how many are filled. Hover previews, half steps are optional, and it is a real radio group (arrow keys, form value), or a plain read-only display with a text alternative. New in Wobko: shadcn has no rating.
npx shadcn@latest add @wobko/ratingFirst time here? Add the registry to components.json first. How to install
Hover to preview, click to choose. It is a radio group: Tab lands on the chosen glyph, then arrow keys, Home and End change the value.
Stars, hearts and suns; `allowHalf` steps by 0.5 (two radios per glyph, one over each half); `max` sets how many; three sizes.
A real-world use: a read-only display (an image with a text alternative, so no tab stop), a form control with `name` and `required`, and a submit that reads the value from FormData.
Several ratings side by side with their own labels and a running summary. Each row is labeled with aria-labelledby; the value text is your own.
The row: `role="radiogroup"` of `max` glyphs (or `role="img"` when read-only). The fill of each glyph is its data-state, so previews and choices only change attributes; nothing is redrawn.
| Prop | Type | Default | Description |
|---|---|---|---|
| value / defaultValue / onValueChange | number / number / (value: number) => void | - | Controlled or uncontrolled value, 0 to max. 0 means none chosen. |
| max | number | 5 | How many glyphs. |
| allowHalf | boolean | false | Steps of 0.5: two radios per glyph (one over each half) and a half-filled glyph, read from the start side. |
| icon | "star" | "heart" | "sun" | "star" | The glyph: a single-stroke pentagram, a wavering heart or a sun with rays. |
| size | "sm" | "default" | "lg" | "default" | 20, 24 or 32 px glyphs. Hit areas are 2 px larger than the glyph on the outer sides, so the row is a row of 24 px targets at least. |
| readOnly | boolean | false | A display: an image with the alt text "Rated 4.5 out of 5" (or your aria-label), no buttons, no tab stop. |
| disabled | boolean | false | Faint pencil glyphs with a graphite fill. The radios are disabled. |
| clearable | boolean | false | A click on the chosen value takes it back to 0. |
| name / required | string / boolean | - | `name` adds a hidden input so the value is in FormData (not while `disabled`). `required` sets aria-required and adds a native input the browser validates, so the form will not submit while the value is 0. A form reset puts the rating back to `defaultValue` (a controlled rating is asked with onValueChange). |
| aria-invalid | boolean | "true" | "false" | - | The empty glyphs are drawn in red pencil (filled ones keep their felt outline). FormControl sets it for you. |
| getLabel | (value: number, max: number) => string | "3 of 5" | The accessible name of each radio. |
| seed | string | number | - | Pins the hand: the same seed always draws the same glyphs. Default: derived from useId(). |
One glyph, `index` counting from 1, to compose your own row inside `<Rating>` (default: `max` of them are rendered for you). It must be inside a Rating.
| Prop | Type | Default | Description |
|---|---|---|---|
| index | number | - | Which glyph of the row this is (1 to max). |
The files the CLI copies into your project.
Loading the source