Focus Next Element In Tab Index

后端 未结 20 1924
失恋的感觉
失恋的感觉 2020-11-27 03:06

I am trying to move the focus to the next element in the tab sequence based upon the current element which has focus. Thus far I have not turned up anything in my searches.<

相关标签:
20条回答
  • 2020-11-27 03:34

    There is the tabindex property that can be set on component. It specifies in which order the input components should be iterated when selecting one and pressing tab. Values above 0 are reserved for custom navigation, 0 is "in natural order" (so would behave differently if set for the first element), -1 means not keyboard focusable:

    <!-- navigate with tab key: -->
    <input tabindex="1" type="text"/>
    <input tabindex="2" type="text"/>
    

    It can also be set for something else than the text input fields but it is not very obvious what it would do there, if anything at all. Even if the navigation works, maybe better to use "natural order" for anything else than the very obvious user input elements.

    No, you do not need JQuery or any scripting at all to support this custom path of navigation. You can implement it on the server side without any JavaScript support. From the other side, the property also works fine in React framework but does not require it.

    0 讨论(0)
  • 2020-11-27 03:34

    refer this pure js npm library for such tab navigation strategies.
    keyboard-navigator
    this small library handles tab key,arrow key navigation,retaining focus on dom updates,modal focus trap, fallback focus.

    0 讨论(0)
提交回复
热议问题