Dynamically inserted content desynchronizes focus unless it is moved on purpose
Aliases: focus after insertion · dynamic focus · stale focus
What it is
A form inserts an error after submit, “Add item” appends a row, a filter replaces a whole block — at those moments the browser does not move focus by default. Focus stays on the button just pressed; the new content appears somewhere else. The keyboard user and the next object that needs handling are no longer in the same place. That is focus desynchronisation after insertion.
Announcing the new content is not the same repair. A live region can make a screen reader speak while focus remains on the old button; the next Tab still walks neighbours of the old location, not the field that just appeared.
Why it happens
The user agent treats focus as “the node the user last chose on purpose”. DOM insertion, Ajax replacement and view swaps are not a deliberate choice, so if the focused node is still in the document it stays put; if it was destroyed, focus often falls to body. Either way both the spatial model and the sequence model break: sighted users hunt between the new block and the old button; users who cannot see hear “there was an error” and Tab into an unrelated region.
Whether focus should move depends on what was inserted. A blocking error, a newly opened dialog, a field the user just asked to create, should become focus. A background “Saved” toast should not steal it. What is missing is that explicit decision — not the browser forgetting to help, the product never writing “the work object changed” as a focus move.
Studying it
Pick three insertions: a validation error, an item appended to a list, a whole result block replaced without a reload. Right after the trigger, ask: which node has focus, where does the next Tab land, did a screen reader speak. Log the three questions separately; do not let “there was a message” stand in for “focus arrived”.
Contrast: the same action on an old full-page-reload site usually puts focus at the top of the new page or on the first field — that is navigation rebuilt, not insertion. Single-page apps that impersonate navigation with insertion desynchronise hardest.
Where it stops holding
Chat rooms, logs and collaborative cursors that stream continuously must not steal focus on every item, or the user cannot type. Notify with a live region; do not move focus. Non-blocking toasts inserted while the user is typing must not take the field either. Conversely, payment failure, permission denied, or an expiring session that inserts a message without moving focus to that operable text leaves a keyboard user hammering Enter on a submit button that already failed.
Applying it
- When inserting a blocking message or a field the user just requested, move focus to that message or field. Changing the DOM is not enough.
- Before destroying the focused node, send focus to a still-existing, task-relevant node. Do not let it fall to
body. - Do not steal focus for a non-blocking “Saved”; a live region is enough.
- How to check: submit a form that will fail, hands on the keyboard. If focus stays on Submit while the error appears at the other end of the screen, desynchronisation has already happened.
Related
- Same group: J3.02.1 Focus order must match visual order · J3.02.2 Overlays must capture focus and remain escapable · J3.02.3 An inescapable focus trap is a blocking defect · J3.02.5 Focus order must update as content expands or hides · J3.02.6 Focus-order failures are found by walking with a keyboard, not by inspecting source order · J3.02.7 Nested overlays that each capture focus can deadlock
- Nearby: J5.12 Live regions and dynamic announcements · J2.07 Low vision and screen magnification · J4.11 Consistency as cognitive support
- Search terms:
focus management·dynamic insertion·focus after update
Cards in the same group
- J3.02.1Focus order must match visual order
- J3.02.2Overlays must capture focus and remain escapable
- J3.02.3An inescapable focus trap is a blocking defect
- J3.02.5Focus order must update as content expands or hides
- J3.02.6Focus-order failures are found by walking with a keyboard, not by inspecting source order
- J3.02.7Nested overlays that each capture focus can deadlock