Star RatingLoading saved progress…

Star Rating

A star rating separates the value a pointer is previewing from the value a user has committed. Build a five-star React control that previews half-star values, commits a value on click, restores the committed value on pointer leave, and remains operable from a keyboard.

Signature

Implement the interaction logic in the default App component in App.tsx. The starter already renders the visual shell and exposes one focusable slider control.

Examples

  • Move over the left half of the third star: the display previews 2.5 / 5 without changing the committed rating.
  • Click that half, then leave the row: 2.5 / 5 remains because the click committed it.
  • With the control focused, press ArrowRight twice: the committed value advances by 0.5 per press. Home clears it to 0; End commits 5.

Notes

  • Keep two state values. rating is committed; hover is temporary. Render hover || rating.
  • Keep commits explicit. Pointer movement updates only the preview; clicks and recognized keyboard keys update rating. Pointer leave clears only hover.
  • Calculate halves from position. Compare nativeEvent.offsetX with half of currentTarget.offsetWidth.
  • Clamp keyboard updates. ArrowLeft/ArrowDown decrease and ArrowRight/ArrowUp increase by 0.5, always within 0..5.
  • Prevent page scrolling. Call preventDefault() for handled slider keys and clear hover before committing the keyboard result.
  • Preserve semantics. Keep role="slider", its ARIA value attributes, the focus target, and the polite text status in sync with the committed rating.
  • Leave styling alone. Persistent styles in styles.css provide the clipped gold overlay and visible keyboard focus ring.
WE’RE LISTENING

Help make UIReady better

Found a bug or have an idea? Tell us about it.

Up to 3 files · 5 MiB each · JPG, PNG, WebP, MP4, WebM, MP3, M4A or WAV