Navigation
The bad
What's wrong with this?
- The menu doesn't have a navigation
role.
- There is no semantic coherence between the menu items.
- The submenu toggle is an
<a>, but should be a <button>.
- Voice Over reads the toggle button's icon aloud.
- The next focus after opening the submenu is not inside it.
- The submenu gets focus even when it's closed.
The good
Show solution
Improvements
- Use
<nav> to wrap the menu to give it a navigation role.
- Label the navigation with
aria-label.
- Put menu items in a list
<ul> to give them semantic coherence.
- Use a
<button> for the submenu toggle to indicate interactivity.
- Use
aria-hidden="true" on the submenu's icon.
- Set
aria-expanded on the toggle button to indicate its state. Make sure to change it when toggling.
- Nest the submenu to ensure correct tab order.
- Remove a closed submenu from tab order with
display: none or visibility: hidden or aria-hidden="true".