Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove HTML tag from tab order

In my app's tab loop, the <html> tag occupies a tab stop. I'm looking to remove the <html> tag from the tap loop.

I tried adding tabindex="-1" to the <html> tag, but on IE11 at least, that did not seem to remove the element from the tab loop. I'm close to spinning my own logic using JS to "skip" to the next focusable element if document.activeElement === <html>, but I'm wondering if there's an easier way.

The solution needs to be supported cross the major browsers: IE11, Edge, FF, Chrome, Safari.

Any ideas?

like image 729
sir_thursday Avatar asked Nov 21 '18 18:11

sir_thursday


People also ask

How do I fix tab order in HTML?

Use the tabindex attribute in HTML to set the tab order of an element. It gives you the authority to change the order of your TAB usage on the keyboard.

How do I get rid of Tabindex in HTML?

The way to do this is by adding tabindex="-1" . By adding this to a specific element, it becomes unreachable by the keyboard navigation.

How do you control tab order?

Change the tab order for controls Use the following procedure to change the tab order of the controls. In the Navigation Pane, right-click the form and then click Design View. On the Design tab, in the Tools group, click Tab Order. In the Tab Order dialog box, under Section, click the section you want to change.

How do I change my Tabindex order?

The only way to change this order is to reorder your HTML elements. tabindex itself can do 2 things: it sets the order of "focusable" elements. it makes element "focusable".


1 Answers

I visited HTML specification for tabindex attribute -> https://html.spec.whatwg.org/#the-tabindex-attribute

Below is the second para:

When the attribute is omitted, the user agent applies defaults. (There is no way to make an element that is being rendered be not focusable at all without disabling it or making it inert.)

As it is clearly mentioned that the only way to make any element not focusable is by making it disable or make it invisible from DOM.

I am still searching and will post an update on this.

Moreover, I also tried to replicate this issue and could not do it on IE.(did not try to replicate on other browser).

Update 1:

I found the difference in tabIndex between HTML4 AND HTML5:

It is stated that though HTML5 allows adding tabIndex attributes on any element, it may not have any effect. This is applicable to HTML element also. My I know, how do we know if an HTML element is focused?

like image 128
Raja Malik Avatar answered Sep 22 '22 18:09

Raja Malik