24
loading...
This website collects cookies to deliver better user experience
:focus-visible
selector, but keep in mind that it’s not yet supported by all the browsers.aria-activedescendant
attribute, and the other one based on tabindex
manipulations. It's a matter of choice which one gets used. However, from the user experience perspective, both are equivalent — the up and down arrows can be used to go through the menu items, and Enter/Space keys can be used to select the currently active item (and thus also close the menu).aria-activedescendant
attribute in such a way that it points to the highlighted menu item using the global ID value of that active menu item.tabindex="-1"
on them. The currently active menu item should have its tabindex set to 0
. When navigating through menu items using arrows, the previous menu item should be excluded from the tab sequence and the next item should be included in it by properly manipulating the tabindex
attribute. To actually move the focus to the next menu item, it is also required that its focus
method be called.tabindex="0"
on the menu button so it can be navigated back to.keydown
listener on the document
element. The listener should check if the Escape key has been pressed, and if yes, then it should close the open element in response to that.