All posts

Where Focus Goes After a Dialog

ai-toolsaccessibilitykeyboard

Backfill note: Written retrospectively on 2026-09-10 for the displayed archive date. This is a design reflection with hypothetical examples, not a report of events on that day.

A dialog closes. To someone using a mouse, the screen may look finished. Someone using a keyboard presses Tab and discovers that the interface has sent them back to the top of the page.

The saved record is fine. The person still has to find their place again.

In a hypothetical task manager, a person opens an edit dialog from a row. The dialog moves focus inside, keeps keyboard navigation within the modal while it is open, and returns focus to the edit button after cancellation. That return makes the next action predictable. The person can carry on near the place they left.

Deletion complicates the return trip. If the dialog deletes the row, its opening button no longer exists. Calling focus on a detached element cannot restore the person's place. The interface needs another destination, perhaps the next row's action button or the list heading when nothing remains.

I don't think one destination fits every screen. The choice depends on the likely next action and the layout. What I object to is leaving the choice to whatever the browser does after the focused node disappears.

An AI agent building this flow can miss the problem by validating only the visible result. A screenshot shows that the row is gone. It doesn't show where the next keypress will land. An automated check can inspect the active element, but I would also walk through the interaction with a keyboard. The order becomes obvious when I have to follow it.

There are awkward cases worth keeping in the test. A filtered list may become empty after an edit rather than a deletion. The opening row may disappear because another user changed it while the dialog was open. An asynchronous save can finish after the person has already cancelled. Restoring focus without checking whether the dialog still owns the interaction can interrupt unrelated work.

I would keep the focus policy beside the dialog behavior, with explicit handling for an opener that has vanished. An acceptance check should name the expected destination after cancellation and after deletion.

The test I want is small: open the dialog without a mouse, finish the action, then continue to the next sensible control. If that last step requires hunting around the page, the dialog has closed before its work is done.