Pick One in a Radio Group
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Build a custom radio group from plain elements, without input elements. A heading "Delivery" labels a role="radiogroup" through aria-labelledby. Inside it, three elements with role="radio" read "Standard", "Express" and "Next day", each with aria-checked "true" or "false". Standard is checked at first, and a line below the group reads "Chosen: Standard". Use a roving tabindex so the group is a single Tab stop: the checked radio has tabIndex={0} and the others tabIndex={-1}. While a radio has focus, the Down and Right arrows move focus to the next radio and check it, and Up and Left to the previous one, wrapping round at both ends. Clicking a radio checks it. After the group comes a "Continue" button.
Your code must pass
- The group is named "Delivery", with Standard checked
- The group is one Tab stop, landing on the checked radio
- Arrow keys move focus and the check, wrapping round
- Clicking a radio checks it, and Tab comes back to it