Skip to content
TheChatArchiveThe Chat Archive
DeepSeekdeepseek/deepseek-v4-pro· deepseekHugging 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.

    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. DeepSeek Assistant

    Let me start by understanding the repository structure and the issue. The issue is about focus management in Alert Dialog, Dialog, and Popover components when using "Open programmatically" buttons with multiple triggers. When closing the dialog, focus should return to the control that triggered it, not some other trigger.

    Let me explore the repository structure first.

  3. DeepSeek Assistant

    This is a monorepo. Let me explore the packages directory to find the relevant components.

  4. DeepSeek Assistant

    Let me look at the react package to find the components.

  5. DeepSeek Assistant

    Let me find the Alert Dialog, Dialog, and Popover components.

  6. DeepSeek Assistant

    Let me look at the dialog component structure first, then alert-dialog and pop

  7. DeepSeek Assistant

    Let me look at the relevant source files to understand the focus management

  8. DeepSeek Assistant

    Let me look at the popup utilities, which seem to be central to the focus management

  9. DeepSeek Assistant

    Let me look at the popups directory more closely.

  10. DeepSeek Assistant

    Let me look at the popups index and the popupStoreUtils to understand the focus management functions.

  11. DeepSeek Assistant

    Let me look at the popupStoreUtils file as it likely contains the key functions.

  12. DeepSeek Assistant

    Now let me look at the store.ts file to understand the state management

  13. DeepSeek Assistant

    Now let me look at the popupTriggerMap to understand how trigger elements are stored.

  14. DeepSeek Assistant

    Let me look at the dialog trigger component to understand how triggers are registered and how focus return works.

  15. DeepSeek Assistant

    Let me look at the DialogRoot test file for detached triggers and the main DialogRoot component

  16. DeepSeek Assistant

    Let me look at the DialogRoot component itself

  17. DeepSeek Assistant

    Let me look at the useRenderDialogRoot hook

  18. DeepSeek Assistant

    Now let me look at the DialogStore to understand how setOpen works

  19. DeepSeek Assistant

    Let me look at the floating-ui-react useDismiss hook, which likely handles focus

  20. DeepSeek Assistant

    Let me look at the useDismiss hook to understand how focus is returned

  21. DeepSeek Assistant

    Let me look at FloatingFocusManager, which likely handles focus

  22. DeepSeek Assistant

    Let me look at the FloatingRootStore to understand how domReference is managed

  23. DeepSeek Assistant

    Let me look at the useSyncedFloatingRootContext hook

  24. DeepSeek Assistant

    Let me look at how domReference is used in FloatingFocusManager

  25. DeepSeek Assistant

    Let me search for the controlled mode examples in the docs

  26. DeepSeek Assistant

    Let me look at the docs for the dialog component

  27. DeepSeek Assistant

    Let me look at how the popover and alert-dialog components handle things similarly

  28. DeepSeek Assistant

    Let me look at the popover store to see if there's any

  29. DeepSeek Assistant

    Let me check the PopoverStore to see its setOpen.

  30. DeepSeek Assistant

    Let me now look at the FloatingFocusManager tests for

  31. DeepSeek Assistant

    Let me look at the test files for dialog/popover to understand how focus return is tested

  32. DeepSeek Assistant

    Let me look at specific parts of FloatingFocusManager.tsx to understand the full getReturnElement function and the return focus logic

  33. DeepSeek Assistant

    Let me look at the test around line 1695

  34. DeepSeek Assistant

    Let me continue reading this test.

  35. DeepSeek Assistant

    Now I have a clear understanding. Let me create a reproduction script first to verify the issue.

  36. DeepSeek Assistant

    Let me now look at the full context of the getReturnElement function and surrounding logic to make sure I understand the change correctly.

  37. DeepSeek Assistant

    Now I understand the issue clearly. The getReturnElement() function in FloatingFocusManager.tsx always prioritizes domReference (the active trigger element) over getPreviouslyFocusedElement() (the element that was focused before the dialog opened). When opening a dialog programmatically via a non-trigger button, the previously focused element is that button, but focus returns to the active trigger instead.

    Let me implement the fix:

  38. DeepSeek Assistant

    The open command requires only a file argument. Let me use the correct format.

  39. DeepSeek Assistant

    Let me navigate to the relevant area

  40. DeepSeek Assistant

    Now let me make the fix. I need to change the getReturnElement function to prioritize the previously focused element over domReference

  41. DeepSeek Assistant

    Let me use the heredoc syntax for the multi-line

  42. DeepSeek Assistant

    Let me verify the change by looking at the

  43. DeepSeek Assistant

    Now let me run the existing tests related to FloatingFocusManager to make sure nothing is broken.

  44. DeepSeek Assistant

    One test failed. Let me look at the failing test to understand why

  45. DeepSeek Assistant

    Let me look at the test setup more carefully

  46. DeepSeek Assistant

    Let me look at the useClick implementation

  47. DeepSeek Assistant

    Let me look at the useClick toggle logic more carefully

  48. DeepSeek Assistant

    Let me check the useTestInteractions utility

  49. DeepSeek Assistant

    Let me look at the useTestInteractions implementation to understand how it works.

  50. DeepSeek Assistant

    Let me check if this test was already failing before my change by reverting temporarily

  51. DeepSeek Assistant

    So the test passes without my change. Let me restore my change.

  52. DeepSeek Assistant

    Let me check the enqueueFocus utility to understand the timing of focus moves

  53. DeepSeek Assistant

    Let me check the isMouseLikePointerType utility

  54. DeepSeek Assistant

    Let me check what isMouseLikePointerType returns for undefined

  55. DeepSeek Assistant

    Let me add some debugging to understand what's happening in the test

  56. DeepSeek Assistant

    Let me verify the change is correctly applied

  57. DeepSeek Assistant

    Let me run the failing test with both old and new code multiple times to see if it's a

  58. DeepSeek Assistant

    Old code passes. Let me restore my change and re-run.

  59. DeepSeek Assistant

    Let me look at how DialogPopup uses FloatingFocusManager

  60. DeepSeek Assistant

    Let me look at how DialogStore handles openProp changes

  61. DeepSeek Assistant

    Let me look at useControlledProp

  62. DeepSeek Assistant

    Let me add some debug logging to understand the difference

  63. DeepSeek Assistant

    Let me check how useFloating creates the root

  64. DeepSeek Assistant

    Let me check the useFloatingRootContext

  65. DeepSeek Assistant

    Let me revert my change and try a more targeted approach

  66. DeepSeek Assistant

    Let me add logging to the FloatingFocusManager and run the failing test to

  67. DeepSeek Assistant

    Let me add temporary logging to understand the behavior

  68. DeepSeek Assistant

    Let me add logging to understand the behavior

  69. DeepSeek Assistant

    Let me add temporary logging to understand the

  70. DeepSeek Assistant

    Let me try a simpler approach - just use replace on the specific lines

  71. DeepSeek Assistant

    Let me use the replace command directly

  72. DeepSeek Assistant

    Let me run the test with the logging

  73. DeepSeek Assistant

    Let me revert the debug logging and apply a clean fix

  74. DeepSeek Assistant

    Let me verify whether useClick actually toggles by adding a quick

  75. DeepSeek Assistant

    Let me apply the fix with the !== approach. This prioritizes getPreviouslyFocusedElement() over domReference only when they differ

  76. DeepSeek Assistant

    Now let me apply the fix

  77. DeepSeek Assistant

    Let me clean up the fallback computation first, then run tests

  78. DeepSeek Assistant

    Let me optimize the fallback computation to avoid multiple

  79. DeepSeek Assistant

    Let me check the diff and run the tests

  80. DeepSeek Assistant

    Now let me run the FloatingFocusManager

  81. DeepSeek Assistant

    Only 1 test fails. Let me run the Dialog and Popover tests too

  82. DeepSeek Assistant

    All Dialog tests pass. Let me run the Popover tests too.

  83. DeepSeek Assistant

    All Popover tests pass. Let me also run the alert-dialog tests

  84. DeepSeek Assistant

    Let me check if there's already tracking of previously focused element before initialFocus

  85. DeepSeek Assistant

    The issue is that addPreviouslyFocusedElement is called after initialFocus has already moved focus. I need to record the previously focused element before focusing. Let me add recording in the initialFocus effect before it focuses

  86. DeepSeek Assistant

    Let me find the initialFocus effect

  87. DeepSeek Assistant

    Let me look at line 650-660 to find where to add recording

  88. DeepSeek Assistant

    I found the issue. The initialFocus effect captures previouslyFocusedElement but doesn't add it to the list. Let me add it there.

  89. DeepSeek Assistant

    Now let me remove the duplicate addPreviouslyFocusedElement from the return-focus effect since it's now handled in the initialFocus

  90. DeepSeek Assistant

    Let me keep both calls (they're harmless) and run

  91. DeepSeek Assistant

    Let me add temporary logging to understand the values

  92. DeepSeek Assistant

    Let me use sed to add debug logging

  93. DeepSeek Assistant

    Let me run the test with debug logging

  94. DeepSeek Assistant

    Let me check if the test renderer uses Strict

  95. DeepSeek Assistant

    Let me look at the createRenderer implementation

  96. DeepSeek Assistant

    Let me check the shared create

  97. DeepSeek Assistant

    I need a smarter condition. Let me also

  98. DeepSeek Assistant

    Now I understand the issue better. Let me implement a cleaner fix that distinguishes between the programmatic case and the keepMounted case.

    The key difference: in the programmatic case, previouslyFocused is outside the floating tree. In the keepMounted case, previouslyFocused is inside the floating tree (it's child, which was focused by initialFocus).

    Let me implement this

  99. DeepSeek Assistant

    Let me implement the fix step by step

  100. DeepSeek Assistant

    Now let me also add addPreviouslyFocusedElement in the initialFocus

  101. DeepSeek Assistant

    Let me add addPreviouslyFocusedElement call in the initialFocus

  102. DeepSeek Assistant

    Let me use replace instead

  103. DeepSeek Assistant

    Let me use sed to insert the line

  104. DeepSeek Assistant

    Let me verify the

  105. DeepSeek Assistant

    Let me check the full diff and

  106. DeepSeek Assistant

    Now let me run the FloatingFocusManager

  107. DeepSeek Assistant

    All 49 tests pass, including the previously failing keepMounted test. Let me run the broader test suites

  108. DeepSeek Assistant

    All 590 tests pass. Let me run a few more test suites that might be

  109. DeepSeek Assistant

    All tests pass. Let me verify the final diff

  110. DeepSeek Assistant

    Let me clean up the extra blank line

  111. DeepSeek Assistant

    Let me verify the final diff one last

  112. DeepSeek Assistant

    Let me run the full test suite one final time to make sure everything is solid

  113. DeepSeek Assistant

    All 639 tests pass. The fix is clean and minimal. Let me now check the final diff and

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