Repository navigation
Define focus restoration for controlled dialogs #1209
Description
Evidence
Merged PR #1205 moved shipping overlays onto the shared Radix-backed Dialog, but the controlled-dialog call sites do not register an opener with DialogTrigger.
Current source has 16 controlled Dialog roots and no shipping DialogTrigger usage. Radix stores the trigger in context.triggerRef, then its modal onCloseAutoFocus handler prevents the browser default and calls context.triggerRef.current?.focus(). Without a registered trigger, that ref is null, so keyboard focus is not restored to the control that opened the dialog.
This is straightforward for colocated single openers, such as the NPM baseline package picker. It is not one mechanical change for every caller:
- Some dialogs are controlled by an opener in a parent component.
- The admin role removal dialog has one dynamic opener per table row.
- Some design-system examples currently keep their opener outside the
Dialogroot.
Repeated title, body, keyword, and open-PR searches found no existing owner. Issue #775 tracks unrelated empty-name, label, landmark, and skip-navigation findings.
Expected impact
Closing a dialog should return keyboard and assistive-technology users to the control that opened it. Falling back to the document body loses their place and makes repeated actions harder.
Proposed direction
Adopt one explicit controlled-dialog focus contract:
- Require
DialogTrigger asChildfor dialogs with one colocated opener. - Add a typed shared API for external or dynamic openers, such as an explicit restore-focus ref or a narrowly exposed Radix close-auto-focus callback.
- Add a browser-level regression test that opens a dialog, closes it with Escape and the close button, and verifies focus returns to the actual opener.
Alternatives and tradeoffs
- Requiring
DialogTriggereverywhere keeps the shared API smallest, but dynamic table-row openers would need dialog state and content moved per row or another structural change. - Restoring the previously active element automatically inside
DialogContentreduces call-site work, but it changes every dialog and can restore focus to a stale or unrelated node when opening is indirect. - Exposing only
onCloseAutoFocusmatches Radix directly, but every caller must repeat the same focus logic and the shared primitive cannot enforce consistency.
Decision needed
@tannerlinsley, should the shared controlled-dialog contract support both DialogTrigger for colocated openers and an explicit restore-focus ref for external or dynamic openers, or should every dialog be restructured so one DialogTrigger always owns the opener?
Source: #1205
Activity
AmirAliAzimloo commentedon Sep 16, 2026
@tannerlinsley Hi, I’m interested in working on this issue. If possible, please assign it to me. I’ll follow up with a pull request once it’s ready.
tannerlinsley commentedon Oct 15, 2026
Coverage note from a fresh source review: #1287 handles the shared API, login modal, NPM baseline picker and dynamic admin role-removal opener. It does not yet cover every caller in this issue.
Remaining call sites include
ExampleDeployDialog,application-starter/DeployDialog,AvatarCropModaland the examples inds.dialog.tsx. The deploy and crop dialogs receive their open state from parents; the design-system examples still place their buttons outside the Dialog root. Those need explicit opener wiring once the shared API lands.I'll keep this umbrella issue open after #1287. The remaining checks should cover Escape, close/cancel and successful completion returning focus to the actual opener, including the crop flow that clears its selected image on close. This list is a source audit, not a claim that those flows have passed browser tests.