Enabling WCAG compliance for a dropdown menu requires keyboard navigability, in addition to mouse functionality. It seems that the bootstrap developers removed sub-menu support some time ago due to mobile unfriendliness, but my specific needs are limited to desktop use.
I attempted to incorporate code from this answer for keyboard navigation, but was unsuccessful in navigating through the submenu.
Upon updating to bs4.5 library, key navigation works perfectly on the top-level dropdown and even reaches the first element in the submenu. However, pressing the up and down keys within the submenu only hides the popup.
Even after preventing the menu from hiding with a keydown
event listener, I am still unsure how to navigate within the submenu as expected utilizing the active
class attribute.
My requirements include:
- Navigating the submenu using UP/DOWN keys
- 'Clicking' submenu elements with the enter key
This is the appearance after activating the submenu with the enter key.
https://i.sstatic.net/CIm1i.png
Here is what happens when moving to the submenu by pressing the down arrow.
https://i.sstatic.net/EZqrz.png
The code (mostly unchanged from the linked question, excluding sub-sub menus):
<html>
<head>
<style>
.dropdown-submenu {
position: relative;
}
.dropdown-submenu a::after {
transform: rotate(-90deg);
position: absolute;
right: 6px;
top: .8em;
}
.dropdown-submenu .dropdown-menu {
top: 0;
left: 100%;
margin-left: .1rem;
margin-right: .1rem;
}
</style>
</head>
<!-- Bootstrap, jQuery, Popper.js -->
</html>
How can I successfully navigate within the submenu?