javascript – Looping tabindex on a div

Question:

The task of such an implementation in angular should be in the form of a controller or directive implementation:

<div>
    <input type="text" name="firstInput"/>
    <input type="text" name="secondInput"/>
    <button>Отправить</button>
</div>

there is a div with fields input[type='text'] it is necessary without leaving the div go through the input s, if after being on the last we click tab on the keyboard, then go back to the first input .

Answer:

Alternatively, find all active elements (at least [tabindex], a[href], object, input, select, button ), save the value there and write -1 . When closing the dialog, return it as it was.

Another option is to handle tab pressing from your code and give focus to the desired element. I say right away that the reliability of this method is in question. And a case that requires a separate check is to click the address bar of the browser with the mouse and press tab there – this case will not fall under your handler and the question is purely about which element of the page will get the focus first.

Scroll to Top