Skip to Content
Puzzle
UI ComponentsData display

Rating

Display and collect star-based ratings with keyboard and pointer support.

Use the Rating component to display a score or let users select one. It supports controlled and uncontrolled values, half-star precision, and a read-only display mode.

Import

import { Rating } from "@puzzle-ui/ui";

Basic usage

Use defaultValue for an uncontrolled rating. The default maximum is five stars.

390 × 100

Controlled value

Pass value and update it through onValueChange when the user selects a rating.

390 × 120

Read-only

Set readOnly when the rating is informational rather than interactive.

390 × 100

Maximum and precision

Set max to change the number of stars. precision controls the smallest selectable increment: 0.5 (default) or 1.

390 × 100

Size and color

Use size to choose sm, md (default), or lg. Override color and emptyColor to match a particular context.

390 × 120

Keyboard interaction

When interactive, the component exposes the slider pattern:

  • Arrow Right / Arrow Up: increase by precision.
  • Arrow Left / Arrow Down: decrease by precision.
  • Home: set the value to zero.
  • End: set the value to max.

The value is clamped to the range from zero to max.

API reference

Rating props

PropTypeDefaultDescription
valuenumber—Controlled rating value.
defaultValuenumber0Initial uncontrolled rating value.
onValueChange(value: number) => void—Called when the rating changes.
maxnumber5Number of stars; integer from 1 to 10.
precision0.5 | 10.5Smallest selectable increment.
size"sm" | "md" | "lg""md"Visual size of the stars.
readOnlybooleanfalseDisplays the value without interaction.
disabledbooleanfalseDisables interaction.
colorstringTheme warning colorFilled and half-filled star color.
emptyColorstringTheme border colorEmpty star color.
aria-labelstring"Rating"Accessible name for the control.
classNamestring—Additional class names on the root element.

TypeScript types

The component exports RatingProps and RatingSize.

Accessibility

Interactive Rating uses the slider pattern with a single tab stop, a meaningful accessible name, and an announced current value.

Arrow keys change the value using the configured precision; Home and End move to the range boundaries.

Read-only ratings are exposed as images with an accessible name that includes the current score.

Star icons are decorative and hidden from assistive technology.

;