A clear score
After the session
Choose a score from one to five, or clear the answer.
Collects a discrete numeric score with 44px native radio choices and an optional clear action.
After the session
Choose a score from one to five, or clear the answer.
Three ways in. They share one source, so the pixels match whichever you pick.
npm install @noorddev/vlak-react
// once, next to your app's root
import "@noorddev/vlak-react/css";
import { Rating } from "@noorddev/vlak-react";Precompiled React and one stylesheet. No compiler to configure. Per-component imports work too: @noorddev/vlak-react/components/rating.
npx @noorddev/vlak-cli add rating
The StyleX leaf lands in components/vlak/ with its dependencies, for your own compiler to own. See StyleX.
npx shadcn add https://vlak.dev/r/rating.json
The same registry item, installed by shadcn's CLI.
<link rel="stylesheet" href="node_modules/@noorddev/vlak/css/vlak.css" />
No React. Link vlak.css and use the markup and classes below.
import { Rating } from "@noorddev/vlak-react";
<Rating label="How useful was this?" name="usefulness" max={5} defaultValue={4} getLabel={(value, max) => `${value} out of ${max}`} />A discrete score using native radios; zero means no rating.
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | ||
defaultValue | number | 0 | |
onValueChange | (value: number) => void | ||
max | number | 5 | |
label | ReactNode | "Rating" | |
getLabel | (value: number, max: number) => string | (score, total) => `${score} of ${total}` | |
clearable | boolean | true | |
clearLabel | string | "Clear rating" | |
required | boolean |
Also accepts Omit<FieldsetHTMLAttributes<HTMLFieldSetElement>, "onChange" | "defaultValue">.
| Keys | Does |
|---|---|
| Tab | Enters the native radio group at its current choice and reaches Clear. |
| Arrow keys | Moves and selects among the native radio choices. |
| Space | Selects a focused radio or activates Clear. |
<fieldset class="rs-rating"><legend class="rs-rating-legend">Usefulness</legend><div class="rs-rating-choices"><label class="rs-rating-choice">1<input class="rs-rating-input" type="radio" name="usefulness" value="1" aria-label="1 of 3" /></label><label class="rs-rating-choice rs-rating-selected">2<input class="rs-rating-input" type="radio" name="usefulness" value="2" aria-label="2 of 3" checked /></label><label class="rs-rating-choice">3<input class="rs-rating-input" type="radio" name="usefulness" value="3" aria-label="3 of 3" /></label></div></fieldset>