← 返回 sofi 的题目列表Star Rating Component
类型:qbank
React and JavaScript UI coding task to implement an interactive five-star rating widget with hover, click, double-click, and half-star behavior.
Requirements
Implement a five-star rating system in React and JavaScript.
On mouse hover, light up stars following the cursor position.
When the mouse leaves, clear the temporary hover state.
On click, set and persist the selected rating.
On double-click, clear the rating.
Support half-star ratings.
A click on the left half of a star counts as 0.5; a click on the right half counts as 1 for that star.
Notes
Keep hover state separate from committed rating state.
Half-star detection depends on pointer position inside the star element, so DOM measurement and event coordinates should be handled carefully.