ValyroUI Русская версия

Rating Input

Star rating. Free, MIT · Forms and input › Checkboxes and sliders

Installation

npx valyro-cli@latest add rating-input
npx shadcn@latest add https://valyro.xyz/r/rating-input.json
npm install valyro-ui

import 'valyro-ui/styles.css';
import { RatingInput } from 'valyro-ui';

Props

PropTypeDefault
valuenumberControlled value; use with onValueChange.
defaultValuenumber0Initial value when uncontrolled.
onValueChange(value: number) => voidCalled with the new value when it changes.
maxnumber5Number of stars.
allowHalfbooleanfalseAllow x.5 values (each star has a left and right half).
readOnlybooleanfalseDisplay only; fractional values like 4.3 render as partial stars.
disabledbooleanfalseDims the stars and ignores input; the rating is not submitted with the form.
size'sm' | 'md' | 'lg''md'Star size: 16 / 20 / 28px.
invalidbooleanfalseEmpty stars turn the danger color (aria-invalid). Also shown after a submit attempt while a required rating is missing.
valueLabelsstring[]Text per whole star, e.g. ["Bad", …, "Excellent"]; shown next to the stars for the hovered or chosen value.
getValueLabel(value: number, max: number) => stringdefaultValueLabelAccessible name of a value (each star, and the whole read-only rating). Default: "4 out of 5".
namestringSubmits the rating with the surrounding form as a number ("3.5"; empty when unrated). Not for readOnly.
requiredbooleanBlocks native form submission while nothing is rated.

Related components

Previous: Histogram Range · Next: Number Input · All Forms and input