The official ARIA APG Listbox example implementation makes extensive use of aria attributes.
Which makes sense as they want to show off how to use them.
Their A11y tree for a single option looks like this:
RootWebArea “Scrollable Listbox Example | APG | WAI | W3C”
- generic
- main
- Section
- generic
- listbox “Transuranium elements:”
- option “Berkelium”
- StaticText “Berkelium”
But usually I would implement the listbox pattern using inputs with type="checkbox"
in a group. This would also match their "No ARIA is better than Bad ARIA" recommendation.
Then the ARIA tree looks like this:
RootWebArea
- generic
- group “Choose your monter’s features:”
- generic
- checkbox “Scales”
My questions now
- If I want to create an ARIA conforming multi-select what is the preferred approach?
- What is the semantic difference between a listbox and a group with checkboxes?
As always, the preferred approach depends, in this case also on your user base.
listboxallows for a bunch of features to navigate a big amount of options, where tabbing through all options would be a pain:So, if you have only a relatively short list, the
group+checkboxwould be a more lightweight solution.ARIA roles allow to communicate to users what they can expect in terms of the widget’s behaviour. This mainly concerns keyboard navigation.
Keyboard Navigation
Here, a simple list of checkboxes, and a list box, differ.
ARIA states for
listbox:In Information for Authors, this is enforced:
This means that inside a list box, arrow keys will control focus between single options, Home and End might jump to the beginning or the end of the list. The APG list multiple other recommended keyboard shortcuts.
In a simple group of checkboxes, only Tab would be used.
Managing focus allows for users to bypass repetitive blocks. If the component is not managing focus and requires Tab keys, don’t use the
listboxrole.Collapsible
A second difference is in
aria-expanded. A list box sometimes can be collapsed and expanded, while thegrouprole does not allow for this attribute.