Skip to content
TheChatArchiveThe Chat Archive
x-ai/grok-4.5· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION Accessibility: Focus moves to the wrong trigger when using "Open…

  1. 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:

    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

    1. Go to [Alert Dialog: Controlled mode with multiple triggers](https://base-ui.com/react/components/alert-dialog#controlled-mode-with-multiple-triggers
    2. Using keyboard, move focus to the "open programmatically" button
    3. Press Enter to activate the control and open the dialog
    4. Press Esc or activate the close button to close the dialog
    5. 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.

    Interface

    No new interfaces are introduced.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /base-ui, current file: none) bash-$

  2. Assistant

    I'll start by exploring the repository structure and understanding how focus is managed in Dialog, Alert Dialog, and Popover components.

  3. Assistant

    Let me explore the packages and find focus-related code for these components.

  4. Assistant

    Let me look at how focus is managed when dialogs close, and how triggers work with controlled mode and multiple triggers.

  5. Assistant

    rg is not available, let me use grep.

  6. Assistant

    There's a detached triggers test and focus-related popup utilities. Let me investigate those.

  7. Assistant

    Let me look more carefully at how dialogs handle multiple triggers and focus return.

  8. Assistant

    Let me inspect DialogHandle open method and how FloatingFocusManager tracks the previously focused element.

  9. Assistant

    Let me check the docs example for controlled mode with multiple triggers.

  10. Assistant

    Let me look at the demo to understand how it works.

  11. Assistant

    The demo associates a trigger programmatically while the focused element is a plain button. I'll inspect how FloatingFocusManager chooses the return-focus target.

  12. Assistant

    Let me look at the return focus logic and how previously focused element is stored.

  13. Assistant

    The manager prefers domReference for return focus. Next I'll check how Dialog sets finalFocus and ties that to the active trigger.

  14. Assistant

    Let me see more of the file around returnFocus.

  15. Assistant

    So finalFocus defaults to undefined, which means returnFocus is undefined in FloatingFocusManager... wait, returnFocus = true is the default when undefined is passed... Actually `returnFocus={finalFoc...

  16. Assistant

    Let me also check the alert-dialog demo and any existing tests about this.

  17. Assistant

    Let me dig into tests and recent focus-return handling more carefully.

  18. Assistant

    Let me inspect how previously-focused elements are tracked and the full return-focus path.

  19. Assistant

    Let me look at more of the return focus cleanup and related tests. Also check floating-ui upstream or change logs for any discussion.

  20. Assistant

    Let me check how the floating root context binds domReference and reopen/close flow tests.

  21. Assistant

    Let me look at the FloatingFocusManager tests for returnFocus behavior to understand expected preferences.

  22. Assistant

    There's a test that nested elements always return to the reference. Let me examine that.

  23. Assistant

    Let me read the unmount and detach-trigger tests related to focus return.

  24. Assistant

    Let me check how controlled open updates the store and whether an event trigger is available.

  25. Assistant

    There's a related comment about controlled focus. Let me keep reading.

  26. Assistant

    Let me check payload and trigger association when controlled open is set.

  27. Assistant

    I'll try preferring the previously focused element and run related tests to see what breaks.

  28. Assistant

    There's a key case about preserving tabbable context next to a removed reference. Let me read that carefully.

  29. Assistant

    Let me look for related issues, PRs, and how the docs →\rightarrow e recommend handling this.

  30. Assistant

    There's a related PR about return focus. Let me inspect that change.

  31. Assistant

    Let me look at that PR's diff.

  32. Assistant

    I'll prefer the previously focused (originating) element for return focus, falling back to the reference. That’s the WCAG-aligned behavior.

  33. Assistant

    Need to navigate to the right line first.

  34. Assistant

    Now I can apply the edit.

  35. Assistant

    Preferring previously focused blindly would break nested dialogs. I'll only use it when it's outside the floating tree.

  36. Assistant

    I need to add the getDefaultReturnElement helper next to getReturnElement.

  37. Assistant

    I need to confirm the layout-effect order so previously focused isn't captured after initial focus moves inward.

  38. Assistant

    Looking at the initial focus effect - does it move focus synchronously or in a microtask/raf?

  39. Assistant

    Initial focus is deferred via microtask, so the originating control is still captured correctly. Next I'll create a temporary reproduction and run the focus-related tests.

  40. Assistant

    I'll add a temporary test for the programmatic-open focus-return case, then run tests.

  41. Assistant

    I'll temporarily add a focus-return test in the detached-triggers file to verify the fix, then remove it before submitting.

  42. Assistant

    Let me see how skipIf isJSDOM is used for focus tests and add my tests after.line 226.

  43. Assistant

    I accidentally added a weird Dialog.Trigger with createDialogHandle - that might break things. Let me fix the test to match the demo more closely.

  44. Assistant

    The parent describe is already skipIf(isJSDOM), so my it.skipIf is redundant. Let me fix the broken test App.

  45. Assistant

    There's an issue - when renders Dialog.Root with open={false}, the triggers are inside the children render prop which onlyr runs when open? LookingLOOKUP at_original \payload t...

  46. Assistant

    Children alwaysrender, good. There's a potential issue: keys to work properly, when pressing Enter on open button which is a plain buttonリラ (not form), it might not fire click. User keyboard En...

  47. Assistant

    The test timed out, likely due to browser startup. I'll retry with a longer timeout.

  48. Assistant

    Piping to tail may be blocking. I'll run the tests without it.

  49. Assistant

    Corepack is prompting interactively. I'll enable pnpm non-interactively and rerun.

  50. Assistant

    Good. Now I'll run the tests.

  51. Assistant

    There was a failure — I'll inspect the full test output.

  52. Assistant

    Playwright browsers are missing — I'll install them next.

  53. Assistant

    Playwright is ready. Running the tests again.

  54. Assistant

    All 21 detached-trigger tests passed. Next I'll run FloatingFocusManager, Dialog, and Popover focus tests.

  55. Assistant

    All passed. FloatingFocusManager skipped many in Chromium — I'll run those under jsdom as well.

  56. Assistant

    Walking only the last stack entry can miss the real originating control (e.g. after a nested tooltip). I'll walk the stack for the last element outside the floating tree.

  57. Assistant

    Updating getDefaultReturnElement to walk the stack for an outside candidate.

  58. Assistant

    Updating getDefaultReturnElement to use the stack walk.

  59. Assistant

    Re-running focus-related tests with the stack-walk change.

  60. Assistant

    Removing the temporary test I added, since new tests aren't allowed in the submission.

  61. Assistant

    Need to open the file first.

  62. Assistant

    I'll restore the test file with git checkout.

  63. Assistant

    Running nested menu/dialog tests once more to confirm no regressions.

  64. Assistant

    Re-verifying the issue scenario quickly, then cleaning up.

  65. Assistant

    Let me add the temp test one more briefly and run.

  66. Assistant

    Run the TEMP test only.

  67. Assistant

    The fix works. Removing the temporary test and submitting.

  68. Assistant

    Reviewing the final change one more time before submit.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.