A focus trap keeps keyboard focus inside an open modal so users cannot interact with background content. It becomes a keyboard trap when users cannot dismiss the modal and return focus to its trigger. Provide a reliable exit, such as Escape or a Close button, so users can move on. section 5.3.4
Check that keyboard users can navigate into and out of interactive elements:
- Press Tab repeatedly through the page, then use Shift+Tab to navigate back. Check that focus can move past custom components such as dropdowns and date pickers. section 5.3.4
const resourceLinks = document.querySelectorAll(".resourceLink");
resourceLinks.forEach((resourceLink) => {
resourceLink.addEventListener("keydown", (event) => { #A
event.preventDefault(); #B
//Some custom logic
...
});
});
This keydown handler calls preventDefault() before custom logic, a pattern that can interfere with default keyboard behavior. section 5.3.4
