Skip to content

Keyboard traps in editors and embedded widgets

A text editor takes over the Tab key to indent, so Tab and Shift + Tab can no longer leave it.

01

The problem

Keyboard users who Tab into the editor cannot Tab out of it, so the rest of the page is out of reach.

02

Try it

Type a note, then press Tab to leave.

Can you reach Save note with Tab, and get back out with Shift + Tab?

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Let Tab leave the editor, or give it a release key that the page describes in text.

  1. 1Tab and Shift + Tab leave the component, directly or after a release key.
  2. 2Describe any release key in visible text, linked with aria-describedby.
  3. 3Never send focus back into a component the user has just left.
Before An editor that keeps every Tab

html

<label for="notes">Notes</label><textarea id="notes" name="notes"></textarea><button type="submit">Save note</button>

js

const editor = document.getElementById('notes');editor.addEventListener('keydown', (event) => {  if (event.key !== 'Tab') return;  event.preventDefault();  editor.setRangeText('  ', editor.selectionStart, editor.selectionEnd, 'end');});
After

Tab moves focus, as the browser intends

html

<label for="notes">Notes</label><textarea id="notes" name="notes"></textarea><button type="submit">Save note</button>

js

// No keydown handler: Tab and Shift + Tab move focus as usual.

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 or any third-party script changes.

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, then 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.

Keep this fixed as your code changes.

Turn guides like this into rules your coding agents and CI follow, then have the result retested with a keyboard and screen readers.

How retests work