JSFiddle - React, Tailwind, and code Playground

HTML

<div>
    radio 1
    <input type="radio" data-mymodaltabindex="1" />
    radio 2
    <input type="radio" data-mymodaltabindex="2" />
</div>
<div>
    text
    <input type="text" data-mymodaltabindex="3" />
    radio 3
    <input type="radio" data-mymodaltabindex="4" />
    radio 4
    <input type="radio" data-mymodaltabindex="5" />
</div>

CSS

.highlight {
   color: red;   
}

JavaScript

$('[data-mymodaltabindex]').on('blur focus', function() {
   var $p = $(this).parent();
   $p.removeClass('highlight');
    setTimeout(function() {
        $p.parent().find('div :focus').parent().addClass('highlight');
    }, 0);
});

$('[data-mymodaltabindex]').on('keydown', function (e) {
    if (e.keyCode == 9 || e.which == 9) {
        // define variables
        var mytabindex = null;
        var maximum = null;
        var minimum = null;
        var next = null;
        var previous = null;
        var values = new Array();
        // set mytabindex on the actual focused control
        var mytabindex = $(this).attr('data-mymodaltabindex');
        // put every visible mytabindex into array
        $('[data-mymodaltabindex]:visible').each(function () {
            values.push(parseInt($(this).attr('data-mymodaltabindex')));
        });
        //console.log(values);
        // look for maximum minimum mytabindex 
        // for maximum and minimum we filter out null values 
        // as they are interpreted as 0 with math functions
        maximum = Math.max.apply(null, values.filter(function (val) { return val !== null }));
        minimum = Math.min.apply(null, values.filter(function (val) { return val !== null }));
        // set next and previous using function
        next = getModalClosestHighValue(values, mytabindex);
        previous = getModalClosestLowValue(values, mytabindex);
        // go back to begining / end if 
        // end / begining is reached
        if (!previous) { previous = maximum; }
        if (!next) { next = minimum; }
        // check if there is shift combination
        if (e.shiftKey) {
            mytabindex = previous; // focus on the previous item
        } else {
            mytabindex = next; // focus on the next item
        }
        // focus on this element
        $('[data-mymodaltabindex=' + mytabindex + ']').focus();
        console.log('focus set to [data-mymodaltabindex=' + mytabindex + ']');
        // stop...