The following are examples of standard checkboxes built with HTML as well as simulated checkboxes built with ARIA
Concepts included in the ARIA checkboxes include:
tabindex="0"
attribute has been added as the checkboxes are built with a <span>
elements which do not receive keyboard focus by default.tabindex
attributes should not be used as it makes it difficult to ensure a consistent focus order as page content is changed and can cause issues for users navigating using a keyboard. It is recommended to only use a value of 0
for tabindex attributes and to ensure content is ordered logically in the DOM.<span>
to convey the element's role.onClick
event has been applied to the simulated checkboxes which supports mouse interaction. This event supports keyboard input via the Enter key on controls such as native HTML buttons and links however is not supported on simulated controls. For this reason, the JavaScript onKeyUp
event has been applied to the simulated controls as well to support keyboard input. This listens for Event Code 32 as that is the code for a Space Bar press, which is the expected behavior of native HTML checkboxes.