Skip to content
TheChatArchiveThe Chat Archive
gpt-5.6-sol· openaiHugging 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. Assistant

    I’ll first inspect the repository structure and locate the focus-restoration logic and tests for Dialog, Alert Dialog, and Popover. Then I’ll reproduce the programmatic-open behavior in the most targeted existing test suite before changing the shared implementation if possible.

  3. Assistant

    ripgrep is unavailable, so I’ll use find/grep. The package metadata confirms a React monorepo with Vitest browser/jsdom projects; next I’m narrowing the search to component roots and shared floating/focus utilities.

  4. Assistant

    The three affected components all use FloatingFocusManager, and their popups currently rely on its default return target (the registered reference/trigger). I’ll inspect the manager’s open/close bookkeeping plus Dialog and Popover state/trigger registration to determine whether the correct fix belongs in the shared manager or component state.

  5. Assistant

    The manager records activeElement when its popup element mounts, which should naturally capture a programmatic opener. However, its close path may deliberately prefer domReference; I’ll inspect that complete block and the popup utility that implicitly selects an active trigger, since that could overwrite the intended target.

  6. Assistant

    The defect is now reproduced directly in code: default return focus unconditionally chooses the registered domReference whenever connected, even though the manager captured the actual element focused immediately before opening. For normal keyboard trigger opens those are the same; for programmatic controls they differ. I’ll inspect the prior-focus stack semantics and existing return-focus tests to safely change precedence while retaining pointer-open and disconnected-origin fallbacks.

  7. Assistant

    A simple precedence swap fixes the reported available-origin case because body is excluded from the prior-focus stack, preserving reference fallback for non-focusing pointer opens. But the issue explicitly requires that if the origin disappears, focus moves next to its former DOM position. I’ll inspect the manager’s existing “preserve tabbable context” mechanism; it may already snapshot adjacent tabbables and only need to use the actual origin rather than the reference.

  8. Assistant

    The “next position” behavior is implemented through portal focus guards tied to the reference’s location, so it does not cover a distinct programmatic opener. To meet the requirement generally, I need a per-manager snapshot of the actual origin and its adjacent tabbable position. Before implementing, I’ll inspect the portal API and tabbable helpers so the fallback follows existing focus-order conventions rather than inventing incompatible traversal.

  9. Assistant

    There is an important API distinction: component finalFocus={() => true} explicitly means “the trigger,” and existing tests enforce that. The default behavior should instead restore the actual opener. Since the manager’s default prop currently collapses “unspecified” and explicit true, I’ll check popup prop wiring and types across affected components, then introduce an internal default mode without changing explicit finalFocus semantics. I’ll also snapshot the next tabbable while the origin still exists for the disconnected-origin case.

  10. Assistant

    I’ll add an internal 'previous' return-focus mode. Dialog/Alert Dialog (shared Dialog popup) and Popover will use it only when finalFocus is unspecified; explicit finalFocus values retain current behavior. The manager will capture the local opener and the next tabbable at mount, prefer the connected opener, then the connected next-position fallback, and finally the registered trigger/global fallback. This avoids relying on the global focus stack for the primary target and supports nested popups correctly.

  11. Assistant

    Python is not installed in the environment, so no files were changed. I’ll apply the same targeted transformations with a temporary Node script, then immediately inspect the diff for accidental documentation/type replacements.

  12. Assistant

    The diff exposed that my documentation insertion matched the initialFocus section rather than returnFocus; I’ll correct that and format the modified files. Then I’ll run the focused manager, Dialog detached-trigger, Alert Dialog root, and Popover detached-trigger suites in Chromium, followed by TypeScript validation.

  13. Assistant

    The source/doc correction completed before the timeout, but Corepack attempted an interactive pnpm download despite dependencies being present. I’ll disable Corepack’s download prompt and rerun; first I’ll verify the formatter did not run partially and inspect the available package-manager binaries.

  14. Assistant

    Corepack is now initialized and the corrected docs are in place. Because terminal calls have a short execution ceiling, I’ll run formatting first, then execute each focused suite separately (rather than one long Vitest invocation), starting with the exact detached Dialog scenario.

  15. Assistant

    Formatting succeeded, but Chromium tests cannot launch because the Playwright browser binary is absent (an environment limitation, not a test failure). I’ll use jsdom for all non-browser-skipped coverage, including the shared focus manager, and run the React package’s type check/lint. I’ll also inspect package scripts to invoke the narrowest validation commands.

  16. Assistant

    The shared manager suite passes in jsdom (49 passed, 2 skipped). To directly verify the reported scenario without adding repository tests, I’ll create a temporary test file, run it, and remove it via a shell trap. It will cover Dialog and Popover programmatic open/close focus restoration, plus removal of the originating button and fallback to the next tabbable control. Alert Dialog shares DialogPopup, so the Dialog path exercises its implementation too.

  17. Assistant

    The temporary test harness failed before exercising behavior because the component module exports a Dialog/Popover namespace rather than parts directly; the trap removed the file, and production code was unaffected. I’ll correct the temporary imports based on existing tests and rerun the exact same behavioral checks.

  18. Assistant

    I’ll rerun with named namespace imports and disable animations, matching the repository test setup. The temporary test remains guarded by automatic cleanup.

  19. Assistant

    The available-origin checks passed for both Dialog and Popover, directly confirming the reported bug is fixed. The fallback test removed the opener synchronously in the same render that opened the popup—before the focus manager could mount and observe it—so no popup-local implementation can identify that detached node or its former position from the resulting DOM. The stated close-time case is when an observed origin becomes unavailable while the popup is open; I’ll adjust the temporary reproduction to remove it during close and verify that supported scenario.

  20. Assistant

    The adjusted removed-origin test passes: when the opener is removed while the dialog is open, focus lands on the next button in its former DOM position. I’ll now run TypeScript for @base-ui/react, then lint only the three changed files and review the final diff/status for generated or temporary artifacts.

  21. Assistant

    TypeScript passes. I’ll run ESLint on the changed files and perform the final diff review, including checking that no temporary tests or build artifacts remain.

  22. Assistant

    The final review found two cleanup/edge issues before submission: the shell trap left both temporary tests untracked, and 'previous' must never treat document.body as a valid origin. I’ll remove the temporary files and add the body guard. I’ll also preserve legacy trigger-open behavior (important in Safari, where pointer-clicked buttons may not receive focus) by selecting 'previous' only when there is no recorded trigger openMethod; genuine trigger opens will continue returning to the active trigger.

  23. Assistant

    The store explicitly resets openMethod on close, so the distinction is not stale across openings. Temporary files are gone and only the three intended source files remain. I’ll rerun the manager plus Dialog/Popover popup suites in jsdom, then repeat type/lint validation after these final edge-case changes.

  24. Assistant

    All focused jsdom suites pass: 119 tests passed and 9 browser-only tests skipped. I’ll perform the final TypeScript, ESLint, formatting check, and repository-status review now.

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