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
So the top-level test runs from repo root with
vitest --project @base-ui/react .... Let's run jsdom project test filtered to our file directly from root.Assistant
Now add a debug log at cleanup and at getReturnElement to see domReference test id.
Assistant
Now run the specific failing test with verbose output to view logs.
Assistant
Let's revert this file and dig into dialog root's trigger/domReference handling to find a more targeted fix location.
Assistant
Now run the full test file again.
Assistant
All pass now. Let's run the broader dialog/popover/alert-dialog/tooltip/preview-card/menu/combobox test suites to check for regressions.
Assistant
All passed. Now let's write a reproduction test scenario using the actual demo pattern to confirm the fix works as intended.
Assistant
The reproduction test confirms the fix works. Let's verify it fails without the fix (sanity check) then remove the temp test.
Assistant
Confirmed: without the fix, focus moves to "trigger-2" (received "Open 2" button); with the fix, focus correctly returns to "Open programmatically". Now clean up the temp test file.
Assistant
Chromium got installed. Let's now run the detached-triggers tests under chromium mode.
Assistant
All the previously-skipped chromium-only tests pass too. Now let's run the full FloatingFocusManager + related test suites under chromium to double check for regressions there as well.
Assistant
Excellent, all pass in the real chromium browser environment too. Let's view the final diff to confirm the change is clean.
Assistant
Good, all imports already present. Now let's run lint/typecheck on the file to make sure there are no issues.
Assistant
These are pre-existing build-cache errors unrelated to our code changes (missing prebuilt
build/outputs), not actual type errors in our new code. Let's confirm no actual semantic type errors by using vitest's type-check-free transform (already passed via successful test runs, which use esbuild/vite transpilation, not tsc). Let's do a quick standalone check withtsc --noEmiton just this single file using a minimal isolated approach.Assistant
Confirmed pre-existing issue unrelated to our change (1094 errors exist even without any modifications, due to missing build artifacts in this environment). Let's check our error count is the same (no new errors introduced).
Assistant
Same count (1094) — confirming our change introduces no new TypeScript errors. Now let's run eslint on the modified file.
Assistant
No lint errors. Let's run a broader final full test pass once more (jsdom) to be safe, including everything under
packages/react/src.Assistant
All 263 test files pass (6103 tests, 873 skipped due to browser-only requirements). Let's also run the chromium-based suite fully as a final sanity check, given it's more thorough for focus-related behavior.
Assistant
Full test suite passes in both jsdom and real-browser (chromium) environments. Let's do a final review of the diff.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.