Tabs¶
Accessible solution for tabs utilizing the following tab design pattern:
- https://www.w3.org/TR/wai-aria-practices-1.1/#tabpanel
- https://www.w3.org/TR/wai-aria-practices-1.1/examples/tabs/tabs-1/tabs.html
- https://www.w3.org/TR/wai-aria-practices-1.1/examples/tabs/tabs-2/tabs.html
Installation¶
pnpm add @mvps-genesis/accessibility
Example Usage¶
First, implement the tabs HTML structure following the example provided in https://www.w3.org/TR/wai-aria-practices-1.1/examples/tabs/tabs-1/tabs.html. Note the following attributes in the example and ensure they are included in the HTML structure:
role
aria-*
id
tabindex
hidden
Once the HTML structure is in place, import the Tabs
class from the @mvps-genesis/accessibility
package in your JavaScript file. Then create a new instance of the Tabs
class.
import {Tabs} from '@mvps-genesis/accessibility';
new Tabs(document.querySelector('.tabs'));
Parameters¶
HTMLElement - containerElement¶
The root container element of the tabs structure.
object - options (optional)¶
The class supports an optional configuration object as a second argument to override any of the default configuration options.
Configuration Options¶
The following table defines the available configuration options:
Name | Type | Description | Default Value |
---|---|---|---|
autoActivate | Boolean | Flag to determine if tab auto activation is enabled or disabled. | true |
autoActivateDelay | Number | Auto activation delay (ms). Applied when autoActivate option is enabled. | 300 |
autoActivate Setting
It is recommended that tabs activate automatically when they receive focus as long as their associated tab panels are displayed without noticeable latency. This typically requires tab panel content to be preloaded. Otherwise, automatic activation slows focus movement, which significantly hampers users' ability to navigate efficiently across the tab list. See the following article for additional guidance on deciding the best choice for this setting https://www.w3.org/TR/wai-aria-practices-1.1/#kbd_selection_follows_focus.
Keyboard Support¶
This section outlines the keyboard support for tab
elements - role="tab"
.
Auto Activate Setting Enabled¶
Key | Function |
---|---|
Tab |
|
→ |
|
← |
|
Home |
|
End |
|
Auto Activate Setting Disabled¶
Key | Function |
---|---|
Tab |
|
Enter Space |
|
→ |
|
← |
|
Home |
|
End |
|
Vertical Tabs¶
When the tablist
element contains the aria-orientation="vertical"
attribute (vertical tabs), the ← and → keyboard support functionality listed above is replaced by the ↑ and ↓ keys respectively.