Improve nav semantics and functionality #73
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The nav block included in the AEM block collection has some accessibility issues that need to be fixed:
aria-expanded
on it in desktop mode even though it's always expanded. This attribute isn't really helpful for screen readers in this context.tabindex
attribute and keyboard events onlistitem
elements that are inaccessible to screen reader users. When navigating with VoiceOver and other screen readers, the text and number of list items are announced but there is no indication these items are interactive.In this PR, I made the following changes:
aria-expanded
to the nav whenisDesktop.matches
evaluates tofalse
. The mobile view is still styled off ofaria-expanded
and marked with the current ARIA state like it was before.button
elements that are keyboard and screen reader interactive. This preserves the list role and semantics for the containing element, while creating an accessible affordance that indicates the correct role, state, and property for an interactive dropdown toggle. The top-level nav items are still interactive with the mouse.By merging these changes into the base repository, every consumer of the code will benefit from a more accessible starting point.
Note: One thing I considered was wrapping the top-level nav item text in a button since the whole thing is clickable (e.g. "Default Content"). But in my own AEM project implementation, I found that wrapping the item text from a
nav-drop
while excluding the UL child is pretty complicated. I chose to keep this version simple intentionally for that reason.Test URLs: