UI

Rating

A bare star rating control with a directional sweep fill, pointer scrubbing, a commit wave pop, and a rolling value readout.

import { RatingInput } from '@uthereal/ui/rating-input'

Rating input playground

Rate the session
Hover, scrub, or click a star to commit.
Loading interactive preview…

Overview

RatingInput renders a labelled, bare star rating control with no surrounding review card, border box, or submit wrapper. Hovering or scrubbing across the stars sweeps a directional fill across each glyph while keeping a faint mark of the committed value underneath. Committing a rating triggers a wave pop across the selected stars and rolls the value readout beside them without shifting adjacent layout.

Your application owns the committed numeric value (0 means unrated) and any surrounding form or submission flow. RatingInput supports whole or half-star precision, scales from 1 to 10 stars, custom whole-star word labels, and a static read-only display mode.

CapabilityBehavior
Scale & precision1 to 10 stars (max, default 5); set allowHalf for 0.5-star steps across pointer, touch, and keys
Pointer scrubbingClick, tap, or drag horizontally across stars; dragging past the leading edge of the first star clears to 0
ClearingEnabled by default (clearable): click the current value again, press Backspace/Delete, or arrow to 0
Value readoutFive whole stars default to Poor–Excellent; other scales show 4.5 out of 5 (override with valueLabels)
Read-only & formsreadOnly renders a static role="img" summary; name emits a hidden <input type="hidden"> for HTML forms

Use RatingInput to capture or display a compact numeric opinion on a star scale. Use Range for continuous numeric sliders, or Number for exact typed quantities.

Usage

'use client'
import { useState } from 'react'
import { RatingInput } from '@uthereal/ui/rating-input'

export function SessionRating() {
  const [rating, setRating] = useState(4)

  return (
    <RatingInput
      label="Rate the session"
      name="session_rating"
      description="Select 1 to 5 stars, or click the active star to clear."
      value={rating}
      onValueChange={setRating}
    />
  )
}

Omit value for an uncontrolled field initialized from defaultValue. When name is set, a hidden <input type="hidden"> submits the current numeric rating (0 when unrated) with the surrounding form unless the field is disabled.

Examples

Half stars and extended scales

Set allowHalf to split each star into leading and trailing half-star hit zones for pointer, touch, and keyboard input. Raise max up to 10 for wider scoring scales, or pass valueLabels to replace the default Poor–Excellent readout.

Sound quality
Likelihood to recommend

Read-only display and disabled state

Set readOnly to present a committed score as a static role="img" without interactive radios; combine it with showValue={false} for compact summary stars. Set disabled to dim the control and remove it from the tab order.

Average rating
4.5 out of 5 across 128 reviews.
Closed survey rating

API reference

These serializable arguments and defaults come directly from the component schema.

ArgumentType / defaultDescription
labelstringDefault: "Rating"Visible field label and accessible name, e.g. "Rate your stay". Sentence case.
hideLabelbooleanDefault: falseHide the label visually when the surrounding interface already names the field. It is still announced.
descriptionstring—Supporting text below the stars, announced with the label. Use it for what the rating is about.
errorstring—Validation message from your application. Setting it marks the field invalid; the message is linked and announced politely.
readOnlybooleanDefault: falseThe stars render as a static image of the value, named e.g. "Rating: 4.5 out of 5". Not editable.
disabledbooleanDefault: falseUnavailable and removed from the tab order.
namestring—Hidden input name, so a native form submit reports the value.
defaultValuenumberDefault: 0Initially committed rating from 0 (unrated) to max. Later argument edits do not reset an existing instance; use value and onValueChange to control it.
maxintegerDefault: 5Number of stars, 1 to 10.
allowHalfbooleanDefault: falsePointer, touch, and arrow keys move in half stars, e.g. 4.5 of 5.
clearablebooleanDefault: trueChoosing the current value again clears it, and Backspace and Delete clear from the keyboard. Without it the minimum is one step.
showValuebooleanDefault: trueShow the word or the number for the current value beside the stars, rolling as it changes.
valueLabelsstring[]—One word per whole star, e.g. Poor, Fair, Good, Great, Excellent. Five whole stars default to those words; anything else reads "4 out of 5".
emptyLabelstringDefault: "Not rated"Shown beside unrated stars, e.g. "Not rated".
sizesm | md | lgDefault: "md"Star size: 18px stars in 28px cells (sm), 24px in 36px (md, default), 30px in 44px (lg).
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeRatingInputTheme—Color mode, accent, and tokens, including the star tint (warning amber by default). See Theming.
motionnone | subtle | expressiveDefault: "subtle"Star sweep, commit pop, press scale, and word roll preset. System reduced-motion preferences take precedence.
motionOptionsRatingInputMotionOptions—The fill sweep (Arc's snappy spring), the committed mark's settle (smooth spring), and the value word roll, as spring or tween transitions with durations in ms; the commit pop keeps Arc's impulse.
dirltr | rtl—Reading direction; the first star sits at the inline start. Omit it to inherit the page direction.

React integration

PropPurpose
value, onValueChangeControlled rating from 0 (unrated) to max. onValueChange fires on every commit in both modes.
refRef to the stars container (role="radiogroup", or role="img" when readOnly is true).
presetApplication defaults (such as size, allowHalf, emptyLabel, theme), overridden by props.
tokensCSS custom properties (--ui-*) applied after the typed theme on the field root.
className, styleApplied to the root field element, which carries the resolved --ui-* tokens.
Native attributesForwarded to the stars container (id, aria-*, data-*, focus/pointer handlers).

The pure formatting and normalization helpers normalizeRatingValue, ratingWords, ratingWordFor, ratingTextFor, ratingSpokenFor, and defaultRatingWords are also exported from @uthereal/ui/rating-input.

Keyboard & accessibility

KeyInteraction
Tab, Shift+TabMoves focus to or from the single roving tab stop in the radio group.
ArrowRight, ArrowUpIncreases the rating by one step (0.5 with allowHalf, else 1); mirrors in RTL.
ArrowLeft, ArrowDownDecreases the rating by one step (down to 0 when clearable is true); mirrors RTL
Home, EndJumps directly to the minimum step or max.
1–9Commits that whole-star value when it is within max.
Space, EnterCommits the focused radio button's value.
Backspace, DeleteClears the rating to 0 when clearable is true and announces "Rating cleared".

In interactive mode, the stars container renders role="radiogroup" labelled by label, described by description and error via aria-describedby, and flagged with aria-invalid when error is set. Each whole or half-star hit zone is a native <button role="radio"> with aria-checked, a descriptive aria-label (for example "Great, 4 of 5 stars"), and roving tabIndex. Commits and clears announce through a pre-mounted role="status" (aria-atomic="true") live region outside the buttons, while the visible rolling readout is aria-hidden="true".

When readOnly is true, the control renders role="img" with a complete aria-label (for example "Rating: 4.5 out of 5" or "Rating: Not rated"), removes all radio buttons from the tab order, and omits form-only attributes (aria-invalid, aria-disabled). In dir="rtl", the star clip-path sweep, half-star hit zones, pointer scrubbing coordinates, and horizontal arrow keys all mirror from the inline start. forced-colors: active maps outlines to ButtonText, filled stars to Highlight, committed marks and disabled stars to GrayText, and focus outlines to Highlight.

Motion and theming

  • Fill sweep and committed mark: hovering or scrubbing sweeps each star's clip-path on motionOptions.sweep (Arc's snappy spring with a 35ms per-star directional stagger), while the committed mark underneath settles on motionOptions.settle (Arc's critically damped smooth spring). Empty stars soften to 0.9 scale and a quiet solid fill once any rating is shown.
  • Press and commit pop: pressing a star compresses it to 0.86 scale; committing hands a physical snappy spring impulse (velocity: 9) to the chosen star or waves across all filled stars when commits are more than 260ms apart.
  • Value word roll: changed words in the value readout roll vertically through a subtle blur on motionOptions.word (240ms enter, 120ms exit) while invisible sizer spans lock the widest label width.
  • Reduced motion: both prefers-reduced-motion: reduce and motion="none" set star fills immediately (0ms), disable commit pops, press and softening scales, word rolls, and CSS state transitions.

theme accepts the core and control token groups, plus borderStrong (resting star outline) and warning (filled star amber; 30% mix for the faint committed mark). An optional UtherealProvider supplies application-wide defaults.

Composition

RatingInput is a leaf component. Its committed numeric rating (0 to max) is host state at /fields/instance-<id>/value, initialized from defaultValue. Stored values survive configuration edits and automatically snap to the updated max and allowHalf step grid. See Building with agents.

{
  "type": "RatingInput",
  "props": {
    "label": "Rate your experience",
    "defaultValue": 4,
    "max": 5,
    "allowHalf": true
  },
  "children": []
}

On this page