Forms
RatingScale
Free13.0 KB gzippedA labeled, single-choice rating scale: faces, numbers (such as a 0 to 10 likelihood scale), or thumbs up and down. Unlike Rating, each option is its own choice with its own name, so choosing one never fills the others. Built on native radios in a role="radiogroup": Tab lands on the selected option, arrow keys move and select, and the value submits with a form.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Arrow keys, Space and 2 more · Full report
Import
import { RatingScale } from "@vjdesigns/vjdesigns-ui";
Importing only RatingScale adds about 13.0 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
Five faces, from very unhappy to very happy. Each face is its own native radio with its own name, so choosing one never fills the others (unlike Rating). sentiment tints them from red to green; the shapes already carry the meaning, so color is never the only cue.
import { RatingScale } from "@vjdesigns/vjdesigns-ui";
export function Basic() {
return (
<RatingScale variant="faces" label="How was your first practice?" showLabels sentiment defaultValue={4} />
);
}
Numbers
numbers runs from min to max, such as the 0 to 10 "how likely" question. startLabel and endLabel caption the ends and are read as part of the description.
Score: none yet
import { useState } from "react";
import { RatingScale, Stack, Text } from "@vjdesigns/vjdesigns-ui";
export function Numbers() {
const [value, setValue] = useState<number | null>(null);
return (
<Stack gap={3} style={{ width: "100%", maxWidth: "40rem" }}>
<RatingScale
variant="numbers"
min={0}
max={10}
label="How likely are you to recommend the league to a friend?"
startLabel="Not likely"
endLabel="Very likely"
value={value}
onValueChange={setValue}
/>
<Text tone="muted">Score: {value ?? "none yet"}</Text>
</Stack>
);
}
Thumbs
thumbs is a two-choice scale for quick yes or no feedback. showLabels puts each option's name under it.
import { RatingScale } from "@vjdesigns/vjdesigns-ui";
export function Thumbs() {
return <RatingScale variant="thumbs" label="Was this article helpful?" showLabels />;
}
In aform
Inside a Field, the scale takes the field's label, hint, error and required, and its value submits with the form like any radio group.
import { useState } from "react";
import {
Button,
Field,
RatingScale,
Stack,
Text,
} from "@vjdesigns/vjdesigns-ui";
export function InAForm() {
const [value, setValue] = useState<number | null>(null);
const [submitted, setSubmitted] = useState(false);
const missing = submitted && value === null;
return (
<form
noValidate
onSubmit={(event) => {
event.preventDefault();
setSubmitted(true);
}}
style={{ width: "100%", maxWidth: "30rem" }}
>
<Stack gap={4} align="start">
<Field
label="Rate the coaching"
hint="1 is poor, 5 is excellent."
required
error={missing ? "Choose a rating." : undefined}
>
<RatingScale variant="numbers" name="coaching" value={value} onValueChange={setValue} />
</Field>
<Button type="submit">Send feedback</Button>
{submitted && value !== null && <Text tone="muted">Thanks! You rated the coaching {value} out of 5.</Text>}
</Stack>
</form>
);
}
Clear and read only
allowClear lets people take back their choice: press the selected option again, or press Delete. readOnly shows a saved rating as one image named "Rated: Happy".
import { RatingScale, Stack } from "@vjdesigns/vjdesigns-ui";
export function ClearAndReadOnly() {
return (
<Stack gap={5}>
<RatingScale variant="faces" label="Your mood today (you can clear it)" allowClear defaultValue={3} />
<RatingScale variant="faces" label="Last week's rating" readOnly defaultValue={4} />
</Stack>
);
}
Sizes and states
size is sm, md or lg. disabled turns off every option.
import { RatingScale, Stack } from "@vjdesigns/vjdesigns-ui";
export function SizesAndStates() {
return (
<Stack gap={4}>
<RatingScale variant="numbers" size="sm" label="Small" defaultValue={2} />
<RatingScale variant="numbers" size="lg" label="Large" defaultValue={4} />
<RatingScale variant="thumbs" label="Disabled" disabled defaultValue={1} />
</Stack>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Basic
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
<Basic />
</LocaleProvider>
API reference
RatingScale
New in 3.8.4| Prop | Type | Default |
|---|---|---|
variantLook and built-in options: five | "faces""numbers""thumbs" | "numbers" |
valueSelected value (controlled). | number | null | — |
defaultValueInitial value (uncontrolled). | number | null | null |
onValueChangeCalled with the selected value, or | (value: number | null) => void | — |
min
| number | 1 |
max
| number | 5 |
optionsCustom options, replacing the variant's built-in set (and | RatingScaleOption[] | — |
startLabelCaption under the first option, e.g. "Not likely". Also read as part of the description. | ReactNode | — |
endLabelCaption under the last option, e.g. "Very likely". Also read as part of the description. | ReactNode | — |
showLabelsShow each option's label under it (faces and thumbs). | boolean | false |
sentiment
| boolean | false |
sizeOption size. Falls back to a surrounding Field's size. | "sm""md""lg" | "md" |
allowClearLet the user remove their choice: clicking (or pressing Space on) the selected option again, or pressing Delete / Backspace, resets it to | boolean | — |
clearHintInstructions announced with each option when | string | "Press Space on the selected rating, or Delete, to clear it." |
disabledDisables every option. Falls back to a surrounding Field's state. | boolean | — |
readOnlyShow the value without allowing changes: a single | boolean | — |
invalidMarks the scale invalid: danger outlines and | boolean | — |
requiredA choice is required: sets native | boolean | — |
nameShared | string | — |
getReadOnlyLabelRead-only: accessible name. Localize it here. | (option: RatingScaleOption) => string | "Rated: Happy" |
unratedLabelRead-only with no value: accessible name. | string | "Not rated" |
labelVisible label, used when the scale stands alone. Ignored inside a | ReactNode | — |
descriptionHelp text under the label, linked with | ReactNode | — |
Also accepts native <div> attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
RatingScale targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10036 passed · 0 failed · 29 not applicable · 10 to check by hand
Dark mode
Score 10036 passed · 0 failed · 29 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Tab | Moves into the scale, on the selected option (or the first), and out of it. The scale is one Tab stop. |
| Arrow keys | Moves to the next or previous option and selects it, as in any native radio group. |
| Space | Selects the focused option; with allowClear, on the selected option it clears the choice. |
| DeleteBackspace | With allowClear: clears the choice. |
Built on native radios, so the value submits with a form and works with Field and useFormValidation. Each option is its own choice with its own name, so choosing one never fills the others.
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Scale | radiogroup | aria-labelledby (the label or Field), aria-describedby (description and the startLabel / endLabel captions), aria-required, aria-disabled |
Option <input type="radio"> | radio | aria-label ("Happy", "7"), aria-describedby (the clear hint, with allowClear), aria-invalid in a Fieldset |
| Face, number or thumb | none | aria-hidden; shapes and text tell options apart, never color alone |
| Read-only scale | img | aria-label ("Rated: Happy", or "Not rated") |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |