Skip to content
h v3.13.3
Search the docs
Find a component, section or page.

Star rating input

A star rating you set, read back or lock, in two sizes.

Installation

pnpm add @heyramzi/ui

Usage

import { StarRatingInput } from "@heyramzi/ui/components/star-rating-input";

Keyboard and accessibility

Key Does
Tab Moves focus to the stars. They are one stop.
Arrow Right Arrow Up Adds a star.
Arrow Left Arrow Down Takes a star off, down to zero.
Home Clears the rating to zero.
End Sets the top rating.
1 2 3 4 5 Sets that many stars.
  • The stars are Bits UI's RatingGroup: a slider from 0 to max, the WAI-ARIA rating pattern.
  • It's named by ariaLabel, or "Rating". Its value reads "3 of 5 stars", plus the step's label when labels is set, or "No rating".
  • Clicking the first star again when it's the only one lit clears the rating.
  • Read-only stars are an image named with the value, like "Rating, 3 of 5 stars".
  • With reduced motion on, the pop on a pick doesn't play.

API reference

value bindable number
Default 0
Current rating value (0 = unrated).
max number
Default 5
Maximum rating. Defaults to 5.
size "sm" | "lg"
Default "sm"
Visual size of each star. `sm` reads back, `lg` asks.
readonly boolean
Default false
Render as static display, no hover or click.
disabled boolean
Default false
Disable interaction.
name string
Form field name for native submission. When set, a hidden input is rendered.
ariaLabel string
What is rated, like "Rate the delivery". The value is added for a screen reader.
labels readonly string[]
Per-step descriptive labels (length must equal max).
showLabel boolean
Default false
Show the label of the currently hovered/selected step beside the stars.
class string
onValueChange (value: number) => void
Called with the new rating after a pick.
Prop Type Default
value bindable

Current rating value (0 = unrated).

number 0
max

Maximum rating. Defaults to 5.

number 5
size

Visual size of each star. `sm` reads back, `lg` asks.

"sm" | "lg" "sm"
readonly

Render as static display, no hover or click.

boolean false
disabled

Disable interaction.

boolean false
name

Form field name for native submission. When set, a hidden input is rendered.

string
ariaLabel

What is rated, like "Rate the delivery". The value is added for a screen reader.

string
labels

Per-step descriptive labels (length must equal max).

readonly string[]
showLabel

Show the label of the currently hovered/selected step beside the stars.

boolean false
class string
onValueChange

Called with the new rating after a pick.

(value: number) => void