Skip to content
TheChatArchiveThe Chat Archive
composer-2.5· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

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

  1. User

    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.

  2. Assistant

    I'll investigate how focus restoration works in Dialog, Alert Dialog, and Popover when multiple triggers are used, starting with the controlled-mode demos and focus-management code.

  3. Assistant

    Implementing the fix in FloatingFocusManager: when closing, prefer the element that had focus at open time over domReference if it isn't a registered trigger.

  4. Assistant

    Implementing the fix and adding a regression test.

  5. Assistant

    Reverting the broad FloatingFocusManager change and implementing a targeted fix via the popup store.

  6. Assistant

    Updating focus return to fall back when the programmatic opener is no longer in the DOM.

  7. Assistant

    Fixed focus restoration when a dialog/popover is opened programmatically while a different trigger is designated as active.

    Root cause

    In controlled mode with multiple triggers, opening via an external button (e.g. "Open programmatically") sets triggerId to a Dialog.Trigger / Popover.Trigger id. On close, focus was returned to that active trigger (domReference) instead of the control that actually opened the popup.

    Fix

    1. focusReturnTarget in popup store — When a popup opens, if the focused element differs from the active trigger, that element is stored as the focus return target.

    2. useFocusReturnTarget hook — Added in Dialog.Root and Popover.Root (covers Alert Dialog too via shared dialog root).

    3. resolvePopupFinalFocus helper — Used by Dialog.Popup, Drawer.Popup, and Popover.Popup to return focus to focusReturnTarget when finalFocus is not explicitly set. If the opener is no longer in the DOM, it falls back to the default trigger behavior.

    Tests

    • DialogPopup.test.tsx: returns focus to the programmatic opener when the active trigger differs
    • DialogRoot.detached-triggers.test.tsx: Chromium test for the same scenario (requires browser env)

    Normal trigger clicks are unchanged: focus and active trigger are the same element, so focusReturnTarget is not set and focus still returns to the trigger.

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