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
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.
| Capability | Behavior |
|---|---|
| Scale & precision | 1 to 10 stars (max, default 5); set allowHalf for 0.5-star steps across pointer, touch, and keys |
| Pointer scrubbing | Click, tap, or drag horizontally across stars; dragging past the leading edge of the first star clears to 0 |
| Clearing | Enabled by default (clearable): click the current value again, press Backspace/Delete, or arrow to 0 |
| Value readout | Five whole stars default to Poor–Excellent; other scales show 4.5 out of 5 (override with valueLabels) |
| Read-only & forms | readOnly 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.
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.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
label | stringDefault: "Rating" | Visible field label and accessible name, e.g. "Rate your stay". Sentence case. |
hideLabel | booleanDefault: false | Hide the label visually when the surrounding interface already names the field. It is still announced. |
description | string— | Supporting text below the stars, announced with the label. Use it for what the rating is about. |
error | string— | Validation message from your application. Setting it marks the field invalid; the message is linked and announced politely. |
readOnly | booleanDefault: false | The stars render as a static image of the value, named e.g. "Rating: 4.5 out of 5". Not editable. |
disabled | booleanDefault: false | Unavailable and removed from the tab order. |
name | string— | Hidden input name, so a native form submit reports the value. |
defaultValue | numberDefault: 0 | Initially committed rating from 0 (unrated) to max. Later argument edits do not reset an existing instance; use value and onValueChange to control it. |
max | integerDefault: 5 | Number of stars, 1 to 10. |
allowHalf | booleanDefault: false | Pointer, touch, and arrow keys move in half stars, e.g. 4.5 of 5. |
clearable | booleanDefault: true | Choosing the current value again clears it, and Backspace and Delete clear from the keyboard. Without it the minimum is one step. |
showValue | booleanDefault: true | Show the word or the number for the current value beside the stars, rolling as it changes. |
valueLabels | string[]— | 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". |
emptyLabel | stringDefault: "Not rated" | Shown beside unrated stars, e.g. "Not rated". |
size | sm | md | lgDefault: "md" | Star size: 18px stars in 28px cells (sm), 24px in 36px (md, default), 30px in 44px (lg). |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | RatingInputTheme— | Color mode, accent, and tokens, including the star tint (warning amber by default). See Theming. |
motion | none | subtle | expressiveDefault: "subtle" | Star sweep, commit pop, press scale, and word roll preset. System reduced-motion preferences take precedence. |
motionOptions | RatingInputMotionOptions— | 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. |
dir | ltr | rtl— | Reading direction; the first star sits at the inline start. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
value, onValueChange | Controlled rating from 0 (unrated) to max. onValueChange fires on every commit in both modes. |
ref | Ref to the stars container (role="radiogroup", or role="img" when readOnly is true). |
preset | Application defaults (such as size, allowHalf, emptyLabel, theme), overridden by props. |
tokens | CSS custom properties (--ui-*) applied after the typed theme on the field root. |
className, style | Applied to the root field element, which carries the resolved --ui-* tokens. |
| Native attributes | Forwarded 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
| Key | Interaction |
|---|---|
Tab, Shift+Tab | Moves focus to or from the single roving tab stop in the radio group. |
ArrowRight, ArrowUp | Increases the rating by one step (0.5 with allowHalf, else 1); mirrors in RTL. |
ArrowLeft, ArrowDown | Decreases the rating by one step (down to 0 when clearable is true); mirrors RTL |
Home, End | Jumps directly to the minimum step or max. |
1–9 | Commits that whole-star value when it is within max. |
Space, Enter | Commits the focused radio button's value. |
Backspace, Delete | Clears 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-pathonmotionOptions.sweep(Arc'ssnappyspring with a35msper-star directional stagger), while the committed mark underneath settles onmotionOptions.settle(Arc's critically dampedsmoothspring). Empty stars soften to0.9scale and a quiet solid fill once any rating is shown. - Press and commit pop: pressing a star compresses it to
0.86scale; committing hands a physicalsnappyspring impulse (velocity: 9) to the chosen star or waves across all filled stars when commits are more than260msapart. - Value word roll: changed words in the value readout roll vertically through a subtle blur on
motionOptions.word(240msenter,120msexit) while invisible sizer spans lock the widest label width. - Reduced motion: both
prefers-reduced-motion: reduceandmotion="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": []
}