☂️ Keyboard navigation with arrow keys #2486
Labels
accessibility
Issues that make it harder, or even impossible, for some specific group of users to use the software
usability
Things that make it harder or easier for users to understand or use elements
New feature motivation
Many users use keyboard to navigate a software's UI. They are either power users, or those who have accessibility needs and rely extensively on keyboard (e.g. due to limited or no vision). Many of our components do not properly support keyboard navigation.
New feature description
Keyboard navigation pattern
When it comes to navigating a user interface, there are at least three major keyboard interactions.
Using ⇥ Tab to focus on the next big thing
What's important here is that tabbing should be done to select or set the focus on the next primary region or on an element inside the primary region in the user interface, for example let's say a bread crumbs component. So once a breadcrumb item has received focus through tabbing, users should also be able to use the arrow keys (usually left and right arrows) to navigate between the breadcrumb items sequentially. This provides a more fluid navigation experience for users who are already focused on the breadcrumb component.
So it is not always right to have individual items inside a component, or a primary region of the UI that are all tabbable. In many cases, (usually in UI components that include an array of similar things, like list items, or buttons) only one of their items should be tabbable. The rest should be navigatable using arrow keys.
What's needed to be able to use ⇥ Tab and set focus on something?
Some elements are natively tababble, like
<button />
s and<a />
s. But most things are not natively tabable, like<li />
s or<div />
s. To make such elements tabable, one need to add atabindex
attribute to them.tabindex
AttributeThe
tabindex
attribute specifies the tab order of an element. It can take three types of values:Positive integer (e.g.,
tabindex="1"
)tabindex
value are added to the natural tab order based on the value of thetabindex
.tabindex="0"
<div>
,<span>
) but need to be focusable due to interactive behavior added via JavaScript.tabindex="-1"
focus()
method), but it is not reachable via sequential keyboard navigation (i.e., it's skipped when tabbing).Screen Readers and
tabindex="-1"
While elements with
tabindex="-1"
are skipped during normal tabbing, they can still be accessed and read out by screen readers when users navigate with mechanisms other than tabbing (e.g., arrow keys). This allows screen reader users to be aware of all elements on the page, even if they aren't in the natural tab order.With a screen reader, the behavior can vary based on the screen reader and its settings. Some screen readers, in their default settings, allow users to navigate to all focusable elements, including those with
tabindex="-1"
. This is because screen readers provide mechanisms to navigate through all elements, not just those in the tab order. However, the common way is that screen readers read out elements withtabindex="-1"
; even if these elements are still skipped when tabbing.New feature implementation
Manipulating the
tabindex
: For components that have an array of tabable items, we need to artificially addtabindex="-1"
andtabindex="0"
, either to override the default tabability (if internal elements natively receive focus using the ⇥ Tab key), or to enable receiving focus using the ⇥ Tab.Which of the items in the array should have
tabindex="0"
(be tabable) depends on what the component is designed to do. But here are a few general guidelines:tabindex="0"
, and everything elsetabindex="-1"
tabindex="0"
, and everything else needstabindex="-1"
.tabindex="-1"
Implementing arrow key navigation: Keep in mind that navigating with arrow keys is not only for non-sighted users. Many keyboard users and power users too use this navigation patterns. Therefore, depending on the direction in which the array of clickable items are laid-out in the user interface (in a column, in a row, or in a grid), two or all four arrow keys are needed to navigate the array. Pressing arrow keys should toggle the
tabindex
accordingly.Which elements would need this improvement
Also, many of our
disabled
clickable elements should get atabindex="-1"
, for improved accessibilityThe text was updated successfully, but these errors were encountered: