What Should Be Avoided
HTML/CSS
<map tabindex="0" name="workmap"> <area shape="rect" coords="34,44,270,350" alt="Computer" href="computer.htm"> <area shape="rect" coords="290,172,333,250" alt="Phone" href="phone.htm"> <area shape="circle" coords="337,300,44" alt="Cup of coffee" href="coffee.htm"> </map> <a href="#next-section">Next Section</a> <script> const map = document.querySelector("map"); const firstArea = document.querySelector("area"); map.addEventListener("keydown", (e) => { if(e.key === "ArrowDown"){ firstArea.focus(); } }) map.addEventListener('keydown', (e) => { const targetElement = e.target; if (e.key === 'Tab') { e.preventDefault(); if (e.shiftKey) { if (targetElement.previousElementSibling?.tagName === "AREA") { targetElement.previousElementSibling.focus(); } else { map.children[map.children.length - 1].focus(); } } else { if (targetElement.nextElementSibling?.tagName === "AREA") { targetElement.nextElementSibling.focus(); } else { map.children[0].focus(); } } } }); </script>
Explanation: In this example, when a user tabs to the "map" element, they can enter the map using the down arrow key. Once inside, they can navigate between clickable areas using the Tab key to move forward and backward. However, there's no clear way for the user to exit the map, creating a navigation trap. This means users will be stuck inside the map indefinitely.