# Focus management

## What it is

Focus management governs where keyboard and assistive-technology interaction is directed as an interface changes. The focused element receives ordinary keyboard actions or participates in the platform's navigation sequence. A user expects to see where focus is and to be able to continue after opening a panel, dismissing a dialog or moving to a new part of a page.

Browsers and native controls provide default movement and activation. Additional focus decisions are useful when a meaningful transition changes the available content. A modal dialog can bring focus inside itself so the user can operate it. When it closes, the application can return focus to the control that opened it or choose a suitable next location if that control no longer exists. The useful destination follows the user's next step.

Visual focus is part of the outcome. The browser can focus an element that is offscreen or under another layer. A programmatic change to focus should leave the target visible and understandable under the actual layout. Responsive changes, overlays and scrolling make this relationship important to test.

## Why it matters

Focus gives a person a place to work. Suppose someone opens a confirmation dialog while processing a list of records. They need a clear indication that the dialog is active and a predictable way to reach the available actions. After cancelling, they should be able to resume from the record they were reviewing. An unexpected move can make a short task take much longer.

Changes can also remove the current point of interaction. A button may disappear once a row is deleted. A filter can replace a list while a person is selecting from it. Focus can move to a stable nearby control or to a meaningful heading when that supports continuation. Choose the expected destination in the design before relying on whichever default a particular browser provides after the element is gone.

Visibility can fail even when focus is set correctly. A sticky toolbar can cover the focused target when the browser scrolls it into view. A visually clipped region can contain links that still receive focus. A person can lose track of the current location despite the page accepting keyboard input. At multiple screen sizes, observe where focus lands and whether the focused element remains visible.

## What it looks like in practice

Consider a dialog opened from a row's action button. When it opens, put focus on a useful initial element in the new context. Some dialogs benefit from focusing a heading or an introductory passage so the user can read before acting. Check the pattern your platform uses and include an available close operation. A modal dialog also needs to manage the keyboard sequence within its active context.

Test cancelling and completing the action. After cancelling, verify that the person can resume at the originating button. After a delete, that button may be gone. Move to a logical next row or a stable list control whose meaning is clear. Record the next element and which scroll position it produces. Repeat the test for the last record, where the proposed next row is absent.

Engineer's case study on rendered accessibility defects describes links that stayed in the tab order while their visible region was clipped. It also records testing additional viewport heights. Those findings apply directly to focus review. Confirm the visible focus point after each transition and run the test in layouts where sticky or clipped regions can change the result.

Also test a late response. A user may move elsewhere while an asynchronous request finishes. If the product automatically moves focus on completion, it can interrupt the task the user chose after the request started. Decide whether a status update can communicate the result while focus stays where the user placed it. Test the case where the original control is no longer focused when the response arrives.

## Where it goes wrong

A focus rule can send every action to the same place even when the outcomes differ. A save might leave the current form available, while a delete removes the row entirely. Make the expected continuation part of each behaviour. Record when focus moves and why. A test should cover keyboard paths as well as pointer-triggered transitions where the browser still has a focused element.

Another issue is keeping hidden controls in the focus sequence. A visual effect can conceal them without changing how interaction reaches them. Inspect the actual controls exposed while each region is open and closed. Check focus visibility on a small screen and after browser zoom or text changes, especially where the layout has fixed-height areas.

Distinguish the next point in the regular Tab sequence from an element that serves as an intentional landing place. A heading can provide useful context after a transition without becoming an extra stop every time a reader tabs through the page. Use the platform's way to assign focus for that transition and check what the next Tab does. An apparently correct focused element can still leave the rest of the sequence confusing if the next action begins far from the user's task.

Finally, pay attention to failures while a UI transition is in progress. A dialog may close without a result. A list refresh may fail and leave its earlier controls visible. Provide a stable continuation for each case. Useful focus management makes the user's position follow the task and leaves visible evidence when the interface changes around it.

## Further reading
* WCAG Focus Order. Describes meaningful sequences for controls.
* WCAG Focus Not Obscured (Minimum). Explains the minimum visibility requirement for focused components.
* WAI modal dialog pattern. Gives expected behaviour for moving and restoring focus.

=> /portfolio/the-accessibility-faults-your-checker-misses/ case study on rendered accessibility defects
=> https://www.w3.org/WAI/WCAG22/Understanding/focus-order.html WCAG Focus Order
=> https://www.w3.org/WAI/WCAG22/Understanding/focus-not-obscured-minimum.html WCAG Focus Not Obscured (Minimum)
=> https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal/ WAI modal dialog pattern

=> https://engineer.company/glossary/focus-management/ This page on the web
