Nudge a Slider with Arrow Keys
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Build a volume control yourself, without <input type="range">: an element with role="slider", aria-label="Volume" and tabIndex={0} so it can take focus, with aria-valuemin="0", aria-valuemax="10" and aria-valuenow set to the volume, which starts at 5. Also show the volume as a line reading "Volume: 5". While the slider has focus, the Right and Up arrow keys raise the volume by 1, Left and Down lower it by 1, Home sets it to 0 and End to 10. It never goes below 0 or above 10. Make the slider the first thing on the page that takes focus.
Your code must pass
- It starts at 5 with its range set
- Tab reaches the slider
- Arrow keys raise and lower it by 1
- Home and End jump to the ends
- It stays between 0 and 10