Skip to content
Aback UI

Rating

A star rating built on native radios, with a read-only display for averages.

BetaUsed in Aback Tools, Aback LaunchRegistry JSON (opens in a new tab)
How useful was this page? (optional)

Not rated yet.

4.6from 128 example reviews

Installation

Copy the source with the CLI to own and edit it, or import it from the npm package.

npx aback-ui@latest add rating

Writes components/ui/rating.tsx. First time in this project? Run npx aback-ui@latest init first, as the installation guide shows.

Usage

Import the parts you need from the installed file. The Code tab above has a complete, working example.

tsx
import { Rating } from "@/components/ui/rating";

API reference

Props and composition points for Rating. Native element props pass through.

PropTypeDefaultDescription
value / defaultValue / onValueChangenumber / number / (value: number) => voidNoneControlled or uncontrolled rating. 0 means no rating.
maxnumber5Number of stars.
namestringNoneForm field name. The checked radio submits its value with a native form.
readOnlybooleanfalseDisplays a value instead of collecting one. Fractions such as 4.5 render as partial stars inside one image with a text alternative.
clearablebooleanfalseA second press on the selected star clears the rating.
size / disabled"sm" | "default" | "lg" / booleanNoneStar size and a disabled state.
getItemLabel / getValueLabel(value, max) => string"3 stars" / "Rated 4.5 out of 5"Accessible names for each option and for the read-only image. Use them to localize.

Dependencies: @tabler/icons-react, plus the shared @/lib/utils helper.

Accessibility

Semantics, keyboard behavior, and the decisions that keep the component operable.

  • An interactive rating is a native radio group, so screen readers announce "3 stars, radio button, 3 of 5" and form submission works without scripts.
  • Name the group with aria-label or aria-labelledby pointing at a visible question.
  • The filled star uses the warning token, which meets non-text contrast. The selected value is also a checked radio, not only a colour.
  • Read-only ratings are one image with a sentence alternative, not five announced icons.

Keyboard

KeyAction
TabEnter or leave the rating.
ArrowRightorArrowUpSelect one more star.
ArrowLeftorArrowDownSelect one fewer star.
SpaceSelect the focused star, or clear it when clearable.

Used in production

The Aback products whose interfaces shaped this component.