Skip to content
TheChatArchiveThe Chat Archive
GLMz-ai/glm-5.2· 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. GLM Assistant

    I'll start by exploring the repository structure to understand the codebase and find the relevant files for the focus restoration issue.

  3. GLM Assistant

    I'll explore the repository structure first.

  4. GLM Assistant

    I need to make single tool calls. Let me explore the dialog directory first.

  5. GLM Assistant

    Now let me look at the utils/popups directory which seems to contain the shared popup logic.

  6. GLM Assistant

    Now let me look at the store and the popupTriggerMap to understand how triggers are tracked.

  7. GLM Assistant

    Now let me find where the focus is being restored after closing the dialog. Let me search for focus management code.

  8. GLM Assistant

    The key file is FloatingFocusManager.tsx. Let me look at how it's used and how returnFocus is passed.

  9. GLM Assistant

    Now let me look at how domReferenceElement is synced from activeTriggerElement.

  10. GLM Assistant

    So here's the key. The useSyncedFloatingRootContext syncs activeTriggerElement to domReferenceElement in the FloatingRootStore. The FloatingFocusManager uses domReferenceElement to return focus.

    So when there are multiple triggers, and the dialog is opened programmatically (e.g. with a button that calls store.setOpen(true)), the activeTriggerElement may not be set to the correct trigger.

    Let me understand the scenario better. The issue is: when you open the dialog programmatically (via "Open programmatically" button that is NOT a trigger, it just calls setOpen), then the activeTriggerElement is set to a different trigger (the first registered one, or the implicit one).

    Let me look at the docs examples to understand the scenario.

  11. GLM Assistant

    So the scenario is:

    1. There are 3 triggers (trigger-1, trigger-2, trigger-3)
    2. There's a separate "Open programmatically" button that sets triggerId to 'trigger-2' and open to true.
    3. When the popover opens, focus should be returned to trigger-2 (the "active trigger").

    But the issue says focus goes back to the wrong trigger. Let me look at the alert dialog demo to understand better.

  12. GLM Assistant

    Let me look at the DialogStore to understand how setOpen works.

  13. GLM Assistant

    Let me look at how the dialog popup uses the FloatingFocusManager and the returnFocus prop.

  14. GLM Assistant

    Let me look at the experiment file that was mentioned and the dialog tests to understand the scenario better.

  15. GLM Assistant

    Let me look at the existing tests for detached triggers to understand the test patterns.

  16. GLM Assistant

    Let me search for existing focus-return tests to understand the patterns used.

  17. GLM Assistant

    Now let me write a reproduction test to confirm the issue. Let me first check how to run a single test file.

  18. GLM Assistant

    Let me look at the test-utils and createRenderer.

  19. GLM Assistant

    Let me check the DialogPopup.test.tsx focus tests setup to understand if they run in jsdom.

  20. GLM Assistant

    These tests run in jsdom. Let me look at how the focus tests are set up - what describe block they are in. Let me look at the focus-related tests.

  21. GLM Assistant

    These focus tests run in jsdom. Let me create a temporary reproduction test.

  22. GLM Assistant

    The Escape key didn't close the dialog. Let me look at how existing tests handle closing and look at the finalFocus test more.

  23. GLM Assistant

    Let me rewrite the test to use the Close button and add a Backdrop, matching existing test patterns.

  24. GLM Assistant

    The dialog is controlled but I forgot onOpenChange. Let me fix the test.

  25. GLM Assistant

    I've reproduced the issue. Focus returns to the "Two" button (trigger-2) instead of the "Open programmatically" button. Now let me understand the FloatingFocusManager's focus tracking order.

  26. GLM Assistant

    Let me look at the initial focus effect that moves focus when the dialog opens.

  27. GLM Assistant

    Let me look at how openMethod is set and how the trigger sets it.

  28. GLM Assistant

    Let me look at the DialogTrigger to understand how it handles focus and openMethod.

  29. GLM Assistant

    Let me check the git history of the FloatingFocusManager to understand what Base UI customized.

  30. GLM Assistant

    Let me look at the test that was added in that commit to understand the "reference disconnects" case.

  31. GLM Assistant

    Let me look at the useButton hook and useClick to understand focus behavior on trigger click.

  32. GLM Assistant

    Let me look at the DialogHandle to understand the handle.open() API and how it sets openMethod.

  33. GLM Assistant

    Let me check the useValueAsRef hook to understand when the ref is updated.

  34. GLM Assistant

    Let me look at the popover trigger and how it handles focus, and check for any focus-on-click logic.

  35. GLM Assistant

    Now I understand the architecture. Let me look at the exact section of the FloatingFocusManager I need to modify.

  36. GLM Assistant

    Now I'll implement the fix. First, let me capture the open interaction type at mount time.

  37. GLM Assistant

    No python. Let me use the edit command instead.

  38. GLM Assistant

    Now let me make the edits. First, capture the open interaction type at mount:

  39. GLM Assistant

    Now let me modify the getReturnElement function to use the captured interaction type:

  40. GLM Assistant

    I accidentally removed the closing brace of getReturnElement. Let me fix that:

  41. GLM Assistant

    The structure looks correct now. Let me run the reproduction test:

  42. GLM Assistant

    The reproduction test now passes. Focus returns to the "Open programmatically" button. Now let me run the existing dialog tests to make sure I didn't break anything.

  43. GLM Assistant

    All dialog tests pass. Now let me run the popover, alert-dialog, and other popup tests that use the FloatingFocusManager.

  44. GLM Assistant

    All passing. Now let me run the other components that use FloatingFocusManager: menu, select, combobox, tooltip, preview-card, drawer.

  45. GLM Assistant

    All passing. Let me run the floating-ui-react tests directly, plus the utils/popups tests.

  46. GLM Assistant

    There's a failing test. Let me look at it.

  47. GLM Assistant

    Let me look at the full test to understand the setup. This is a non-modal focus manager (modal={false}). It uses disabled={!isOpen} and opens via fireEvent.click(reference). There's no openInteractionType passed. So openInteractionType defaults to '' (empty string).

    Let me look at the broader test setup.

  48. GLM Assistant

    The failing test uses FloatingFocusManager directly without openInteractionType (defaults to ''). My check treated '' as programmatic. Let me examine how Base UI components pass openInteractionType to understand the right signal.

  49. GLM Assistant

    The Menu and Select don't pass openInteractionType (defaults to ''). So I need to treat '' (default) as "trigger interaction" (old behavior), and only null as "programmatic". Let me check the combobox's openMethod handling.

  50. GLM Assistant

    I see - Menu and Select don't pass openInteractionType (defaults to ''), and direct FloatingFocusManager usage in tests also defaults to ''. The Base UI components pass openMethod which is null when programmatic. So I should treat null as programmatic, and everything else (including '') as a trigger interaction. Let me update the check:

  51. GLM Assistant

    Now let me re-run the FloatingFocusManager tests and the reproduction test:

  52. GLM Assistant

    Both pass now. Let me re-run the full set of affected component tests to make sure everything is consistent:

  53. GLM Assistant

    All tests pass. Now let me verify the fix handles the popover and alert-dialog scenarios too, and check edge cases. Let me look at the PopoverPopup's FloatingFocusManager usage first.

  54. GLM Assistant

    The popover passes returnFocus={finalFocus} (default true) and openInteractionType={openMethod}. My fix should apply. Let me write more comprehensive tests covering popover, alert-dialog, the handle.open() case, and the edge case where the originating control unmounts.

  55. GLM Assistant

    All 4 tests pass. Now let me test the popover scenario, which may be non-modal by default. Let me check the popover's modal default.

  56. GLM Assistant

    The popover is non-modal by default. Let me write a popover test mirroring the docs demo to verify the fix works there too.

  57. GLM Assistant

    The popover test passes too. Now let me test the edge case where the originating control unmounts while the dialog is open (focus should fall back gracefully).

  58. GLM Assistant

    All 5 tests pass, including the edge case. Let me verify the fix is actually responsible by temporarily reverting it and confirming the tests fail. Let me use git stash.

  59. GLM Assistant

    The fix is confirmed responsible - without it, 3 programmatic-open tests fail. With it, all pass. The disconnect fallback case passes both ways (returns to trigger).

    Now let me clean up the temporary test files (I must not add new tests to the repository).

  60. GLM Assistant

    Now let me review the final diff of my change.

  61. GLM Assistant

    The diff is clean. Let me verify TypeScript compiles correctly for the react package.

  62. GLM Assistant

    TypeScript compiles cleanly. Let me run a final comprehensive test of all affected components.

  63. GLM Assistant

    All tests pass (3006 passed, 0 failed). Let me run eslint on the modified file to ensure no lint issues.

  64. GLM Assistant

    There's a lint error - the effect is missing the openInteractionTypeRef dependency. This is consistent with the existing pattern (the initial focus effect already includes openInteractionTypeRef, and returnFocusRef is in this effect's deps). Let me add it:

  65. GLM Assistant

    Now let me re-run eslint and the FloatingFocusManager tests to confirm:

  66. GLM Assistant

    Lint passes now. Let me run the FloatingFocusManager tests and the dialog tests once more to confirm nothing regressed with the dep change:

  67. GLM Assistant

    All pass. Let me run prettier to verify formatting, then do a final review of the complete diff.

  68. GLM Assistant

    Let me verify the Drawer also sets openMethod via its trigger (so the null signal is consistent across all popup components).

  69. GLM Assistant

    The DrawerTrigger is an alias for DialogTrigger, so it sets openMethod the same way. All Base UI popup components (Dialog, Popover, Combobox, Drawer) pass openMethod which is null when programmatic. Let me do a final check for any other FloatingFocusManager usages I might have missed.

  70. GLM Assistant

    All usages covered. Let me do one final broad test run including toolbar (which nests menus) to be thorough.

  71. GLM Assistant

    All tests pass. Let me do a final verification of the git status to ensure only the intended file is modified.

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