Skip to content
easeweb
Search topics

Keyboard traps in editors and form fields

A text editor takes Tab to indent, or an email field pulls focus back until the address is valid, so Tab and Shift + Tab can't leave.

WCAG 2.2
SC 2.1.2A
Required by
Section 508 · EN 301 549 (EU)
Broken event.preventDefault()
The accessibility problem illustrated: Motor:How do I get out?
01

The problem

Keyboard users who Tab into the editor, or into the email field before typing a valid address, cannot Tab out, so the rest of the page is out of reach

02

Try it

Move through the page with the keyboard alone, and see whether you can always get out again

  • Broken 1: type a note. Can you reach Save note with Tab, and get back out with Shift + Tab?

  • Broken 2: Tab into Email address and press Tab again, then try once more after typing “name@”. Can you reach Subscribe, or get back out with Shift + Tab?

  • Apply a fix. Try the same keys again. Can you reach Save note or Subscribe with Tab, and get back out with Shift + Tab, even with the address left empty?

Broken Can you fix this?

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Let keyboard focus leave the editor and the field

Before

An editor that keeps every Tab

<label for="notes">Notes</label><textarea id="notes" name="notes"></textarea><button type="submit">Save note</button>
What is wrong3 points
  • Tab can't move on. Every Tab, with or without Shift, is cancelled and turned into two spaces.
  • People are stuck in the editor. Focus can't leave it with the keyboard.
  • People looking for another way out find no clue. The page says nothing about another key.
After

Tab moves focus, as the browser intends

<label for="notes">Notes</label><textarea id="notes" name="notes"></textarea><button type="submit">Save note</button> <label for="email">Email address</label><input id="email" name="email" type="email" required aria-describedby="email-error"><p id="email-error"></p><button type="submit">Subscribe</button>
How it is fixed3 steps
  1. Remove the editor's keydown handler. A textarea already lets people type, and the browser moves focus out of it on Tab and Shift + Tab.
  2. Remove the field's focus() call. The field still checks the address when focus leaves it and shows the message, then lets focus go.
  3. Keep required and type="email". They still stop the form from being sent with a wrong address: the browser moves focus to the field at that point, because the person asked to send.

This fixes both Befores, and both the editor and the field pass 2.1.2. It is the smallest change, and nobody has to learn a special key. If people need indentation, add an Indent button or indent automatically when they press Enter.

Why this fix: Use native HTML first

04

Verify the fix

5 checks, no mouse.

Test with: Keyboard, Screen reader

0 of 5 checked

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the editor, the form's validation or any third-party script changes.

How screen readers handle aria-describedby

Limits

This is a starting pattern, not a guarantee for every application. The snippet indents with two spaces and leaves out undo and outdenting. Rich-text and code editor libraries have their own Tab settings; check what yours does. An editor that can be left but isn't read with the label shown beside it is covered in rich text editors announced without their label.

A trap can also sit in a third-party widget, such as an embedded player, a map or a chat window, including one in shadow DOM or an iframe. The script isn't yours to change, but the page still fails 2.1.2, whoever wrote it. Look for it on the live page with the widget loaded, not in your own templates. Report it to the vendor with the steps to reproduce it and the criterion, give another way to do the same task beside it, such as a link or a phone number, and replace the widget if it isn't fixed. Test the complete journey with a keyboard and your target assistive technology.

This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.

EaseWeb service

Fixed it? Keep it from coming back.

I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.

See the service