How to build custom form controls - need help with enldess list cycling

Hi there!
I’ll appreciate any help on this small task posed here https://developer.mozilla.org/en-US/docs/Learn/Forms/How_to_build_custom_form_controls

(please find on this page the line “We’ll leave adding this missing functionality as a reader exercise.” just to get an idea what I’m asking for.
Here’s my version for possible solution https://github.com/BrendanWorley/customformcontrolmodified/tree/main
However it only works in Firefox other browsers don’t do it the supposed way.

So, the question is how one would make prevent endless cycling through the list of options.

Thank you.