Focus Management
Focus management deliberately controls where keyboard focus moves, remains, and returns as an interface changes.
Download Markdown (.md)Soroush’s Product Wiki · https://wiki.soroush.uk/topic/focus-management/
01What it means
Focus is the active point of keyboard interaction. Good management relies on a logical DOM order by default and moves focus programmatically only when dynamic changes would otherwise leave users lost—for example, opening a modal, adding an error summary, or removing the focused item.[1][2][3]
- TriggerUser opens, adds, removes, or submits
- Context changesDialog, summary, replacement, new region
- Place focusLogical initial or surviving target
- Navigate visiblyKeyboard path remains understandable
- Close or resolveReturn to a logical control
Restore focus and preserve the user's task context
Ordinary navigation should follow meaningful DOM order; focus and selection are distinct states.
02Why it matters
Predictable focus lets keyboard and screen-reader users understand where they are and continue a task efficiently. Poor focus handling can place users behind overlays, reset them to the document start, hide the active control, or announce changed content without a usable next action.
03When to use it
Plan focus behavior for dialogs, menus, route changes, validation, inserted content, deletion, composite widgets, and any interaction that changes context. Specify initial focus, containment if needed, exit behavior, and the return target.
04How it works
- Preserve semantic DOM order and let native browser behavior handle ordinary navigation.
- Define the trigger, initial focus target, internal navigation, and return target for dynamic components.
- Move focus only when it supports the user’s next task or communicates a context change.
- Keep the focused element visible and distinguish focus from selection.
- Restore focus to a logical surviving control when content closes or is removed.
- Test forward and reverse navigation, zoomed layouts, errors, and assistive technologies.
05A practical example
When a user opens a confirmation dialog, focus moves to its heading or safest actionable control, Tab stays within the modal interaction, Escape closes it when appropriate, and focus returns to the button that opened it. If that trigger was deleted, focus moves to a logical nearby control.
06Where it breaks
Programmatic focus can be disruptive when used to compensate for weak structure or to steer users aggressively. Screen readers have multiple navigation modes, and visual focus styling has separate requirements; focus movement should be tested rather than inferred from code.
Common mistakes
- Moving focus on every content update.
- Opening a modal while leaving focus behind it.
- Returning focus to an element that no longer exists.
- Confusing selected, active, hovered, and focused states.
- Using aria-activedescendant without implementing visual and keyboard behavior.
07Sources
- Developing a Keyboard InterfaceW3C Web Accessibility Initiative · Technical guidanceDeveloping a Keyboard Interface
- Understanding Success Criterion 2.4.3: Focus OrderW3C Web Accessibility Initiative · Standards guidanceUnderstanding Success Criterion 2.4.3: Focus Order
- Understanding Success Criterion 2.4.13: Focus AppearanceW3C Web Accessibility Initiative · Standards guidanceUnderstanding Success Criterion 2.4.13: Focus Appearance