Reputation: 183
I was wondering if someone could explain to me, from an accessiblity standpoint, the logic behind explicitly giving menu item anchors a tab index of -1. I want to give my menu items a tab index of 0 because their natural order is the order that I want. Are there any drawbacks to this strategy?
Upvotes: 0
Views: 1304
Reputation: 613
As other answerers have pointed out, it's to remove sub-menu items from the tabbing order, while still providing keyboard access to it via other means.
Here is a detailed description of an accessible menu, touching on both the WAI-ARIA attributes and tabindex: Recommended WAI-ARIA implementation for navigation bar/menu
Upvotes: 1
Reputation: 3297
tabindex="-1"
takes it out of the order, BUT allows the keyboard focus to be moved there by a script.
The jQuery menu is an example of a WAI-ARIA menu widget which has a specified keyboard interaction.
Briefly, the menu should be one tab-stop in the tabbing order, and then you use arrow keys to navigate the menus. That is why -1
is a useful value, you can script the movement of keyboard focus using the arrow keys. Using 0
would break the interaction model, so I wouldn't use the jQuery menu if you want to change it in that way.
I have found in usability testing that few people know about this interaction (i.e. they get stuck), at least for 'standard' sites which are mostly content with one WAI-ARIA widget. It is different for things like gmail, where people (may) expect a more application-like experience.
If you are looking for a menu in the website sense of navigation, I would recommend the Adobe OS mega-menu, which uses a combination of standard-scripting and a few ARIA attributes to provide a great experience for regular websites.
Upvotes: 3
Reputation: 17753
The jQueryUI team has put a lot of effort into accessibility lately and the tabs widget is keyboard navigable:
Keyboard
Honestly, I'd recommend not mucking with what they've come up with.
Upvotes: 1
Reputation: 5840
A tabindex of -1 is used to exclude an element from the tab order entirely.
Example
<input type="text" tabindex="1" />
<input type="text" tabindex="2" />
<input type="text" tabindex="-1" />
<input type="text" tabindex="3" />
See this fiddle for an example
It is fine to use that. See the W3C HTML5 specification:
If the value is a negative integer
The user agent must set the element's tabindex focus flag, but should not allow the element to be reached using sequential focus navigation.
I'd say that (from an accessibility standpoint) this approach makes most sense when:
or
As for your question regarding the usage of "0" as a tabindex:
In the HTML specification it says:
Elements that have identical tabindex values should be navigated in the order they appear in the character stream.
Meaning that you could use any value other than 0 as long as all the elements you want to give a natural tab order to, all have the same tabindex.
Upvotes: 0
Reputation: 271
This prevents the element from being part of the sequential navigation focus. It is best to assume it is not a tab worthy item then to set an index which would be undesirable when done incorrectly.
Even for the scenario of a readonly field that shows a calculation sum. If you have a user tabbing to each entry they shouldnt have to tab twice to bypass the readonly field
Upvotes: 0