You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code examples you provide do not show how the dropdown is hidden once you've tabbed away from it. I can get it to show and hide when clicking the arrow icon, but once you tab down the submenu times and onto the next menu item, yours hides, mine doesn't. I'm using the same code as you've shown.
Please either explain or modify the code.
Thanks.
Resource Shortname
wai-tutorials
The text was updated successfully, but these errors were encountered:
It seems like there is more codes being applied to the menu then the ones shown in the tutorial. To close the dropdown when you tab out of the dropdown links, you would need to add a blur event listener to the links, something like this.
varmenuItems=document.querySelectorAll("li.has-submenu");Array.prototype.forEach.call(menuItems,function(el,i){varactivatingA=el.querySelector("a");varbtn='<button><span><span class="visuallyhidden">show submenu for “'+activatingA.text+"”</span></span></button>";activatingA.insertAdjacentHTML("afterend",btn);el.querySelector("button").addEventListener("click",function(event){if(this.parentNode.className=="has-submenu"){this.parentNode.className="has-submenu open";this.parentNode.querySelector("a").setAttribute("aria-expanded","true");this.parentNode.querySelector("button").setAttribute("aria-expanded","true");}else{this.parentNode.className="has-submenu";this.parentNode.querySelector("a").setAttribute("aria-expanded","false");this.parentNode.querySelector("button").setAttribute("aria-expanded","false");}event.preventDefault();});constsubmenuLinks=el.querySelectorAll("ul li a");if(submenuLinks.length===0){return;}submenuLinks.forEach((a)=>{// Add a blur event listener on the sub menu link.a.addEventListener("blur",function(event){consttimeout=setTimeout(function(){if(el.classList.contains("open")&&a.closest("ul").matches(":not(:focus-within)")){el.classList.remove("open");el.querySelector("a").setAttribute("aria-expanded","false");el.querySelector("button").setAttribute("aria-expanded","false");}},10);});});});
Resource URL
https://www.w3.org/WAI/tutorials/menus/flyout/
Description
Approach 2:Use button as toggle
The code examples you provide do not show how the dropdown is hidden once you've tabbed away from it. I can get it to show and hide when clicking the arrow icon, but once you tab down the submenu times and onto the next menu item, yours hides, mine doesn't. I'm using the same code as you've shown.
Please either explain or modify the code.
Thanks.
Resource Shortname
wai-tutorials
The text was updated successfully, but these errors were encountered: