Focus Trap
A focus trap occurs when keyboard focus becomes confined within a particular region or component, such as a modal dialogue, menu, or interactive widget, preventing the user from navigating out. While focus trapping is intentional in some cases (for example, when a modal dialogue is open), it becomes a serious accessibility barrier if there is no way to escape or close the component.
Proper focus trapping involves ensuring that when a modal or menu is open, the focus remains inside it, looping through its content until the user closes it, usually with the Esc key or a close button. Once closed, focus should return to the element that triggered the modal.
Inaccessible focus traps typically occur when developers use JavaScript to manage components but fail to handle focus correctly, causing keyboard users to become “stuck.”
An accessible focus management system ensures users can freely enter and exit interactive components without losing their navigation context, maintaining both usability and independence.