Focus Management
Deliberately controlling which element receives keyboard focus as an interface changes.
Focus management is the deliberate control of what has keyboard focus as the interface changes. For anyone navigating by keyboard or screen reader, focus is their position in the page — losing it means losing their place entirely, usually back at the top.
The obligations are straightforward to state. Opening an overlay moves focus into it. Closing it returns focus to whatever opened it. Removing the focused element moves focus somewhere sensible rather than letting it fall to the document body. Navigating to a new view announces and focuses the new content.
Return-focus is where implementations usually break, and the cause is subtle: capturing the currently focused element on open is not enough if the opener is unmounted while the overlay is showing. The captured node is detached by the time you try to restore, and focusing a detached node silently does nothing. The fix is an explicit reference to the remounted opener rather than a captured node.
A companion bug: a return-focus effect that also fires on first mount, with nothing having been opened, steals focus on every page load. Guarding on "has actually opened once" is the fix, and the case worth testing explicitly.
Component tests can catch a lot of this, provided the test harness reproduces the real structure — a demo whose opener stays mounted will pass while the real application is broken.
See also8
Hand-picked in the note itself — the neighbours worth reading next.
Focus Trap
Confining keyboard focus inside a modal surface so it cannot wander behind it.
Design & Interface10 connections
Keyboard Navigation
Making every interactive affordance reachable and operable without a pointer.
Design & Interface12 connections
Accessibility
Designing so that people with disabilities can use a thing, and the standards that make it checkable.
Design & Interface20 connections
Component Story
An isolated rendered instance of a component, usable as documentation, a workbench, and a test.
Testing & Verification15 connections
Portal
Rendering an element into a different part of the document than its logical parent.
Web Platform14 connections
Document Object Model
The live tree of objects a browser builds from a document, and the surface every UI framework writes to.
Web Platform12 connections
Headless Component
A component supplying behaviour and accessibility with no styling of its own.
Design & Interface13 connections
contenteditable
The HTML attribute that makes an element directly editable, and the surface behind most rich-text editors.
Web Platform11 connections
Related2
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from14
Notes elsewhere in the wiki that reach for this one.
- AccessibilityDesign & Interface
Designing so that people with disabilities can use a thing, and the standards that make it checkable.
- ARIADesign & Interface
Attributes that describe roles, states, and relationships to assistive technology when HTML cannot.
- Component StoryTesting & Verification
An isolated rendered instance of a component, usable as documentation, a workbench, and a test.
- contenteditableWeb Platform
The HTML attribute that makes an element directly editable, and the surface behind most rich-text editors.
- Document Object ModelWeb Platform
The live tree of objects a browser builds from a document, and the surface every UI framework writes to.
- Focus TrapDesign & Interface
Confining keyboard focus inside a modal surface so it cannot wander behind it.
- Headless BrowserTesting & Verification
A real browser driven programmatically without a visible window.
- Headless ComponentDesign & Interface
A component supplying behaviour and accessibility with no styling of its own.
- Keyboard NavigationDesign & Interface
Making every interactive affordance reachable and operable without a pointer.
- PortalWeb Platform
Rendering an element into a different part of the document than its logical parent.
- Reduced MotionDesign & Interface
An operating-system preference signalling that animation should be minimised, for real medical reasons.
- Semantic HTMLDesign & Interface
Using elements for their meaning, so the document conveys structure without extra description.
- Stacking ContextDesign & Interface
The nested coordinate system that decides what paints above what, and why z-index often does nothing.
- Staggered AnimationDesign & Interface
Offsetting the start of sibling animations so a group reveals in sequence.