Accessibility: Focus moves to the wrong trigger when using "Open programmatically"…
- User
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
Now let me look at the detached triggers tests to understand expected focus behavior:
- Assistant
Now let me check PopoverPopup and AlertDialogPopup:
- Assistant
Now let me implement the fix in
FloatingFocusManager.tsx: - Assistant
Now add the ref declaration near the other refs:
- Assistant
Now update
getReturnElement: - Assistant
Now clear stale
openEventon prop-driven closes inuseSyncedFloatingRootContext: - Assistant
Now let me check the structure of the detached triggers test file to add a regression test:
- Assistant
Now let me add a regression test to the detached triggers test file:
- Assistant
Now let me run the tests. First the FloatingFocusManager tests in jsdom:
- Assistant
Tests pass. Let me verify the new test actually catches the bug — temporarily disable the fix:
- Assistant
The test correctly fails without the fix. Restoring:
- Assistant
Now run the broader test suites that could be affected — dialog, alert-dialog, popover, and floating-ui-react:
- Assistant
All popover tests pass on re-run (earlier failure was flaky). Let me run it once more to confirm stability, plus menu and select suites:
- Assistant
All test suites pass. Now run typecheck and lint:
- Assistant
All checks pass. Let me summarize the changes:
Summary
Problem: In Alert Dialog, Dialog, and Popover controlled mode with multiple triggers, opening the popup programmatically (e.g. an "Open programmatically" button that sets + ) and then closing it moved focus to the designated trigger (/) instead of the control that actually had focus when the popup opened — a WCAG 2.4.3 (Focus Order) concern.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.