Skip to content

Rating

Star rating control with optional half-star precision and a hover preview.

  • stable
  • since v0.1.0
  • 2.09 kB
  • forms

Exposes role="slider" with aria-valuemin/max/now; arrow keys, Home, and End adjust the value.

Preview
Open
tsx

Three sizes are available: sm, md (default), and lg.

Preview
Open
tsx

Set max to the number of stars to display. 5 is the default.

Preview
Open
tsx

Set allowHalf to capture 0.5 increments — the click position within each star determines whether you commit a half or full.

Preview
Open
tsx

Set readOnly to render the value statically. disabled removes the field from the tab order.

Preview
Open
tsx

Use renderValue to render a trailing slot that reflects the current (or hovered) value.

Preview
Open
tsx
PropTypeDefaultDescription
value
number
Controlled current value, 0..`max`.
defaultValue
number
Uncontrolled initial value.
onValueChange
((value: number) => void)
Fires when the user clicks or keys to a new value.
max
number
5
Maximum number of stars.
allowHalf
boolean
false
Allow half-star increments.
size
"sm"|"md"|"lg"
"md"
Control size.
disabled
boolean
false
Disables interaction and removes the control from the tab order.
readOnly
boolean
false
Renders stars but blocks user interaction.
required
boolean
Marks the field as required for form submission.
name
string
Submitted form field name (renders a hidden input).
id
string
label
string
"Rating"
Accessible label.
aria-label
string
renderValue
((value: number, max: number, previewValue: number) => ReactNode)
Render a trailing slot (e.g. numeric label). `previewValue` is the currently-hovered value, or `undefined` when not hovering.
className
string
style
CSSProperties
  • The root exposes role="slider" with aria-valuemin={0}, aria-valuemax={max}, and aria-valuenow.
  • Keyboard: Arrow Up/Right and Down/Left adjust by step (1 by default, 0.5 when allowHalf); Home/End jump to bounds.
  • readOnly sets aria-readonly; disabled sets aria-disabled and removes the field from the tab order.
  • Clicking the active value again clears the rating (sets it back to 0).
  • Use defaultValue for review forms; switch to controlled (value/onValueChange) when the value lives in form state.
  • Provide a clear label or aria-label so screen readers announce what is being rated.
  • Use renderValue to surface a numeric readout (e.g. “4.5 / 5”) next to the stars.