Skip to content

Keyboard Trap Detection in Navigation Tests ​

This document explains how our accessibility testing tool detects and handles keyboard navigation patterns that may indicate traps or unexpected behaviors.

How It Works ​

The tool focuses on analyzing the sequence of elements that receive focus when navigating with Tab and Shift+Tab. Specific patterns have been implemented to identify anomalous behaviors.

Detection Patterns ​

The following patterns have been added to detect keyboard traps on the page:

Pattern A→B→A→B: Detecting Two-Element Cycles ​

This pattern identifies a situation where keyboard focus alternates repeatedly between two specific elements (A and B). This can occur if the page's navigation logic is misconfigured, preventing the user from escaping this cycle.

Example Sequence: ​

  • Focus is on element A.
  • Pressing Tab moves focus to element B.
  • Pressing Tab again returns focus to element A.
  • Pressing Tab once more brings focus back to element B.

Pattern A→B→C→A→B→C: Detecting Three-Element Cycles ​

Similar to the previous pattern, this detects a focus cycle involving three distinct elements (A, B, and C). A cycle of this nature also indicates a problem with keyboard focus management.

Example Sequence: ​

  • Focus is on element A.
  • Pressing Tab moves focus to element B.
  • Pressing Tab again moves focus to element C.
  • Pressing Tab once more returns focus to element A.
  • Pressing Tab again moves focus to element B.
  • Pressing Tab once more moves focus to element C.

Pattern A→A→A→A: Detecting Single-Element Repetition ​

This pattern triggers when keyboard focus remains on the same element (A) consecutively, despite the user attempting to navigate to other elements. This can happen if an element persistently captures focus or if navigation is blocked.

Example Sequence: ​

  • Focus is on element A.
  • Pressing Tab keeps focus on element A.
  • Pressing Tab again, focus remains on element A.
  • Pressing Tab once more, focus continues on element A.

Detection Process ​

The tool records the sequence of elements that receive focus during navigation. Upon detecting any of these patterns, an alert is generated indicating the presence of a keyboard trap. This allows developers to identify and fix accessibility issues related to keyboard navigation.