Skip to content

Bug: Focus restore after elements are reordered does not work in child windows #30864

@ling1726

Description

@ling1726

This affects various Microsoft products that use child windows, and is an accessibility bug for users because focus is lost when they interact with an app and the active element is moved in DOM by React.

React version: 18.3.1

Steps To Reproduce

  1. Clone the repro repo https://github.com/ling1726/react-child-window-focus-repro
  2. Run npm install
  3. Run npm run dev
  4. Open the demo app in http://localhost:5173/
  5. Reorder the items with ArrowUp and ArrowDown
  6. Open example in child window
  7. Reorder the items with ArrowUp and ArrowDown
  8. Notice that focus is lost immediately after reordering

Recording:
focus repro

Link to code example: https://github.com/ling1726/react-child-window-focus-repro

The current behavior

The current getActiveElementDeep always uses the global window keyword. Note this snippet is from the React codebase

function getActiveElementDeep() {
let win = window;
let element = getActiveElement();
while (element instanceof win.HTMLIFrameElement) {
if (isSameOriginFrame(element)) {
win = element.contentWindow;
} else {
return element;
}
element = getActiveElement(win.document);
}
return element;
}

This fails focus restore when the active element is moved by React because it never gets the correct active element in a child window.

The expected behavior

When React moves an active element it should restore focus to the active element in a child window

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions