1. FOCUS Flashcards
¿What is focus? (theoric explanation)
Focus refers to the control on the computer screen that receives input from the keyboard and from the clipboard when you paste.
Example: in order to type in a text field you first have to go over with your mouse and click on it. Well that act of clicking on the text field, that’s actually what focuses it. You may also know that if you then press the tab key it will then move focus to the next text field or available control.
¿Why all the page functionality should be available using the keyboard?
Unless it’s something you couldn’t normally do with a keyboard like free hand drawing or something like that, all page functionality should be available using the keyboard because some users drive the computer entirely with the keyboard or some other type of discrete input device.
(For those users, focus is absolutely critical. It’s their primary means of reaching everything on the screen)
¿What is focus? (Technical explanation)
Focus determines where keyboard events go in the page.
¿How does focus is indicated?
The currently focused item is often indicated by a focus ring, where the actual styling of that ring depends on the browser and any additional styling that the page author may have applied.
Working with native elements
Working with native elements is great for focus behavior, because they’re automatically inserted into the tab order based on their position in the DOM.
Tip por TAB ORDER
To tab through my page every so often just to make sure I haven’t accidentally messed up the tab order.
¿Where can tabindex be used?
Tabindex attribute can be used when there are instances and you want to modify their tab order.
(Like if you’re building a component without a native analog (like a drop down), or if you need to have something off screen that should only be focusable when it appears, like perhaps a modal window)
¿Where can tabindex be applied?
Tabindex can be applied to any HTML element, and it takes a range of numeric values.
Tabindex of -1
A tabindex of -1 means that the element will not be in the tab order, but it can be programmatically focused via JavaScript, by calling the element’s focus method.
(This can be especially useful for off screen content which appears on screen in response to a user event.
When the new content is displayed, you may wish to call its focus method which will then direct future keyboard events to it.)
Tabindex of 0
A tabindex of 0 will add the element to the natural tab order, plus, that element will also be focus full by calling its focus method.
(For example, here I’ve got a fancy button that I’ve created out of just a div. Now, without a tabindex attribute, if I press the Tab key, this element will not receive focus. By adding a tabindex of zero, now when I press the Tab key, this element gets focused, and future keyboard events get directed to it)
A tabindex of greater than zero
A tabindex of greater than zero, for instance something like tab index of 5 will jump the element to the front of the tab order regardless of where it is in the DOM.
(If there are multiple elements with a tabindex greater than zero, the order will start from the lowest value that is greater than zero and then work its way up.
In general, using a tabindex greater than zero is discouraged and considered a bit of an anti-pattern)
About tab order
If you need to put something earlier in the tab order, the best bet is to move it up in the DOM.
¿What may I add focus behavior to?
Normally, you only want to add focus behavior to interactive controls like buttons, tabs, drop downs, or anything that the user might provide input to, not our site content.
So when you’re adding a tab index attribute, stop and ask yourself, is this something the user is going to interact with?
¿Which Elements Should Have Focus?
The following elements should have focus.
- Header links
- Search fields
- Form input fields
- Submit button
- Large Call to Action button,
- Footer links.
About tabindex and the Site Content
I mentioned previously that you shouldn’t add tab index to site content as a general rule.
But there is one exception to this and that’s when you’re manipulating the page, in response to a user action.