• Success Criterion 2.1.2
  • Conformance level A

Script That Yanks Focus Back Every Time the User Tabs Away

2.1.2 — No Keyboard Trap

Scenario

Setting

A job board's application form

What’s wrong

focus() handlers yanking focus back whenever the user tabs away (auto-refocus traps).

Example

// modal traps Tab inside with no Escape handler

Why it matters

All keyboard and screen-reader users who can become stuck inside a component.

How to test

Tab away from a control: if a focus() handler yanks focus back immediately, you're trapped in a loop and can never move past it.

How to fix

Focus must always be able to leave the component using Tab/Shift+Tab or Esc (or a standard method the user is told about). document.addEventListener('keydown', e => { if (e.key === 'Escape') closeModal(); }); Any component that captures focus needs a standard way out — Escape, or focus cycling back to a close control.

Outcome

On a job board's application form, this barrier is gone for all keyboard and screen-reader users who can become stuck inside a component — they reach the same outcome without extra effort.

Who is affected

All keyboard and screen-reader users who can become stuck inside a component.

Learn more