The document discusses strategies for improving the accessibility of button dropdowns in web applications, particularly for keyboard-only users and screen reader compatibility. It covers various aspects such as using appropriate HTML elements, implementing ARIA attributes, and ensuring proper keyboard navigation for dropdown interactions. The content includes specific code examples and best practices to enhance user experience and accessibility.
My main rolein recent times is to work on the UX/UI and front-end development of Pattern Libraries for web applications.
4.
However, I alsowork in the Accessibility space. My focus in this area is helping developers build accessible web components for complex Web apps.
5.
One web componentthat can present accessibility issues is the button dropdown.
6.
A button dropdownis where a button is used to trigger the display of contextual menus - such as a list of links.
7.
A diagram showinga button “Weyland Industries” with no dropdown displayed
8.
A diagram showinga button “Weyland Industries” with the dropdown displayed below. The dropdown displays three options: “Weyland Industries”, “Stark Industries” and “Cyberdyne Systems”
9.
We’re going tolook at a range of possible checkpoints that could help make button dropdowns more accessible.
10.
We’ll use animaginary example of a button dropdown that allows users to switch their current organisation.
11.
A diagram showinga button “Weyland Industries” with the dropdown displayed below. The dropdown displays three options: “Weyland Industries”, “Stark Industries” and “Cyberdyne Systems”
The fundamental differencebetween buttons and links is that buttons should do something (cause something to happen), and links should go somewhere (go to a different location).
16.
The markup forthe dropdown depends on the role of the items inside. If the items are a list of links, then an unordered list of links is ideal.
This is important,as it tells screen reader users that it is a different type of button - not a normal button associated with submitting a form etc.
26.
<button type="button" aria-‐label="Current company: Weyland Industries. Use the dropdown menu to switch companies" aria-‐haspopup="true" > Weyland Industries </button>
27.
The aria-‐expanded="false" attribute canbe used to announce the current state of the popup button to screen readers - i.e the dropdown below the button is not currently expanded.
28.
The "false" valuewould need to be changed to "true" via JavaScript as soon as the user triggers the button.
29.
<button type="button" aria-‐label="Current company: Weyland Industries. Use the dropdown menu to switch companies" aria-‐haspopup="true" aria-‐expanded="false" > Weyland Industries </button>
30.
Alternatively, the aria-‐ expanded="true"attribute could be injected via JavaScript only when the button is triggered - which would reduce the amount of information being announced.
<button type="button" aria-‐label="Current company: Weyland Industries. Use the dropdown menu to switch companies" aria-‐haspopup="true" aria-‐expanded="true" > Weyland Industries </button>
This is somethingthat most button dropdown solutions do not solve elegantly. In many cases, users trigger the button but the focus does not shift at all.
39.
Users are eithergiven silence after they trigger the button, or the button information is repeated again. This can cause confusion for users who cannot see that the dropdown has been triggered, but nothing has been announced.
40.
The <ul> elementcould be given an aria-‐label value, which means that when it receives focus, it’s purpose is announced.
A side note: Ifthe current organisation exists in the long list of dropdown items, it may be a good ideal to flag this item as the current organisation for screen reader users.
43.
This can beachieved with a range of different methods, including providing additional information that is hidden off-screen.
When focus hasshifted to the <ul> element, keyboard-only users should be able to use TAB, SHIFT TAB, UP ARROW or DOWN ARROW to move forwards or backwards through the list items.
49.
When users reachthe start or end of the list, UP ARROW and DOWN ARROW keystrokes should then have not have any effect.