ISSUE DESCRIPTION Accessibility: Focus moves to the wrong trigger when using "Open…
- User
ISSUE DESCRIPTION
Accessibility: Focus moves to the wrong trigger when using "Open programmatically" buttons
Current behavior
In the Alert Dialog, Dialog and Popover components, there is a variant that includes the option to use multiple triggers to open the dialogs. When using the "Open Programmatically" button to open the dialog/popup, then closing it, focus moves to a different control than the one that triggered the dialog/popup.
See:
- [Alert Dialog: Controlled mode with multiple triggers](https://base-ui.com/react/components/alert-dialog#controlled-mode-with-multiple-triggers
- Dialog: Controlled mode with multiple triggers
- Popover: Controlled mode with multiple triggers
This could cause failures against WCAG 2.2 Success Criterion 2.4.3 Focus Order when implemented.
Expected behavior
Keyboard focus should move back to the originating control (if available) when closing a dialog as long as a page refresh or redirection is not triggered.
If the control is no longer available, focus should move next to that originating control's position in the DOM.
Reproducible example
- Go to [Alert Dialog: Controlled mode with multiple triggers](https://base-ui.com/react/components/alert-dialog#controlled-mode-with-multiple-triggers
- Using keyboard, move focus to the "open programmatically" button
- Press Enter to activate the control and open the dialog
- Press Esc or activate the close button to close the dialog
- Note focus has moved back to the "Delete" button and not the "open programmatically" button as expected.
Base UI version
v1.2.0
Which browser are you using?
Chrome 145.0.7632.76
Which OS are you using?
Mac OS Tahoe 26.2
Which assistive tech are you using (if applicable)?
Keyboard
Additional context
Recommend keeping track of focus and returning it to the originating control.
- Assistant
I’ll trace the shared dialog/popover trigger and focus-restoration logic, identify how programmatic opens differ from trigger opens, then implement the smallest shared fix and run the relevant tests. I’ll also inspect the repository’s existing tests and conventions before editing.
- Assistant
The shared
FloatingFocusManagercurrently resolves default return focus todomReferencefirst. With multiple triggers, a controlled/programmatic open can leave that reference pointing at another trigger even though the control that had focus is the true origin. The manager already records the previously focused element and already handles disconnected targets; I’ll make the default target prefer that recorded element, retaining the reference as fallback for cases where no prior focus exists (including hover behavior). - Assistant
The first broad change exposed an existing expectation: ordinary floating elements must still return to their reference when focus has moved inside the floating content. I refined the behavior so the previously focused element is used only when it is an external origin distinct from the reference; this fixes programmatic external controls without changing normal trigger/child behavior. The focused-manager suite now passes (49 passed, 2 skipped). I’ll run the dialog/popover suites and inspect the final diff.
- Assistant
Implemented the focus restoration fix in
FloatingFocusManager.Changes
- Default focus restoration now prefers the externally focused element that initiated a programmatic open.
- Existing behavior remains unchanged for standard trigger-based opens and focus moved inside the popup.
- The DOM reference remains a fallback when no originating element is available.
Verification
FloatingFocusManagertests: 49 passed, 2 skipped- Dialog/popover detached-trigger tests: 28 passed, 54 skipped
git diff --check: passed
Checklist
- Reproduced/analyzed the reported issue through the shared focus-management logic.
- Confirmed the fix with the affected focus-manager tests.
- Considered edge cases, including normal trigger opens, focus inside the popup, and missing originating elements.
- Ran relevant existing tests successfully.
I’m submitting the changes now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.