4. Interactive WAI-ARIA (Basic)
The remainder of the book is hands-on. You’ll be taking inaccessible widgets, like the example of toggle buttons described here, and making them accessible by adding appropriate WAI-ARIA and keyboard operability. The toggle buttons widget demonstrated here is provided as an example for the ten widgets you will be working on over the next three chapters, describing the Activity Elements you will find in each exercise.
Roles, states, and properties for toggle buttons
- aria-label="[button name]"
tabindex to each button to make them keyboard focusable, define the
role="button", and add a label with
aria-label="[button name]" and set the default state to “not pressed” with
Add in equivalent keyboard access where mouse access is provided, referencing the
onActivate() function, described below, with jQuery
aria-pressed="[true|false]" for buttons when activated or deactivated to announce the button’s state to screen readers.
Adding Keyboard Operability
Keyboard access for the buttons is fairly simple, with no special key press events needing to be defined.
Keyboard Interaction for Toggle Buttons
When the button has focus:
- Space: Activates the button.
- Enter: Activates the button.
- Following button activation, focus is set depending on the type of action the button performs. For example:
- If activating the button opens a dialog, the focus moves inside the dialog (see dialog pattern).
- If activating the button closes a dialog, focus typically returns to the button that opened the dialog unless the function performed in the dialog context logically leads to a different element. For example, activating a cancel button in a dialog returns focus to the button that opened the dialog. However, if the dialog were confirming the action of deleting the page from which it was opened, the focus would logically move to a new context.
- If activating the button does not dismiss the current context, then focus typically remains on the button after activation, e.g., an Apply or Recalculate button.
- If the button action indicates a context change, such as move to next step in a wizard or add another search criteria, then it is often appropriate to move focus to the starting point for that action.
- If the button is activated with a shortcut key, the focus usually remains in the context from which the shortcut key was activated. For example, if Alt + U were assigned to an “Up” button that moves the currently focused item in a list one position higher in the list, pressing Alt + U when the focus is in the list would not move the focus from the list.
No added keyboard interaction is required for the toggle buttons beyond the standard Space bar and Enter key defined in the ik_utils.js file. Reference to these key events is added to the
Accessible Toggle Buttons in Action
The buttons are accessed initially with the Tab key, and the Tab key is used to move between buttons. The Space bar or Enter keys are used to activate and deactivate buttons. Aim to have the widget you edit in the associated activity function like that presented in the video (there is no associated activity for this example).
Video: Accessible Toggle Buttons