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
Playwright browser installed. Now let's run the reproduction test.
Assistant
Reproduced the bug: focus goes to "Two" (trigger-2) instead of "Open programmatically" button. Now let's implement the fix in FloatingFocusManager.tsx.
Assistant
Now let's implement the fix:
Assistant
Let me use the heredoc syntax for replace instead.
Assistant
Fix works. Now let's run the existing detached-triggers tests plus broader related test suites (dialog, popover, alert-dialog, menu, select, combobox, drawer) to check no regressions.
Assistant
All passing. Now run broader test suites.
Assistant
All tests pass. Now let's also run the full jsdom test suite for a broader sanity check, and specifically the floating-ui-react FloatingFocusManager tests fully (not skipped) to confirm no regressions there.
Assistant
All jsdom-only tests pass, including the important "returns focus to reference when floating element was opened by hover" and "focus does not return to reference when floating element is triggered by hover" tests. Let's also run the full jsdom test suite for the whole react package to catch any broader regressions.
Assistant
Confirmed. All consumers already tested. Now let's also verify the fix works for Popover and AlertDialog with detached-trigger controlled mode scenario, mirroring the demo exactly, plus verify Escape key closing (not just Close button click).
Assistant
Works for Escape too, and for AlertDialog with handle-based triggers. Now let's clean up test file and check Popover similarly, plus verify normal single-trigger behavior remains correct (focus returns to actual trigger clicked, not something else).
Assistant
Both regular usage and detached-trigger controlled mode work correctly. Let's clean up the temp test file.
Assistant
Good, only the intended source file is modified. Let's view the final diff.
Assistant
No type errors. Let's double check with git diff and file state once more, then run the lint for this file.
Assistant
No lint errors either. Let's do a final review of the diff and confirm git status is clean apart from the intended file.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.