It looks good, the html structure is solid, and the styling looks good.
The toggle button has good focus styling, but it doesn't work from the keyboard properly. A checkbox should respond to pressing spacebar, but you're only listening for <enter>
in the script file.
Instead of adding two separate event listeners for keydown
and click
, you could listen for change
which will fire whenever the user checks or unchecks the toggle. This will then retain all the accessibility features of the native <input type='checkbox'/>
Marked as helpful
@CoderPr0
Posted
@AlexKMarshall I wasn't aware of that, thank you for the tips. :)