Skip to content
Frontend live coding · 20 minutes

Star rating input

Build a star rating input in React in 20 minutes. It shows five stars. The user chooses a rating from 1 to 5 with the mouse or with the keyboard, and hovering shows a preview. It must work in a form and for a screen reader user. Decide first which HTML to build on: a group of radio inputs gives you most of the keyboard and screen reader behavior without extra code. Explain your decisions while you code, as in a live round.

Requirements

  • Five stars; a click on a star sets the rating to its number
  • Hovering over a star shows a preview up to that star; when the pointer leaves, the selected rating shows again
  • Keyboard: the Tab key reaches the control, and the arrow keys change the rating
  • A screen reader hears a group name, and for each star a name such as '3 stars' and whether it is selected
  • The API has value and onChange, and optional name and disabled props
  • The focus indicator is visible on the stars, also when the real inputs are visually hidden

What reviewers look for

What reviewers look for, the checklist and the stretch goals opens with a year in the app. What a year includes