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
- Clone the repro repo https://github.com/ling1726/react-child-window-focus-repro
- Run
npm install
- Run
npm run dev
- Open the demo app in
http://localhost:5173/
- Reorder the items with
ArrowUp and ArrowDown
- Open example in child window
- Reorder the items with
ArrowUp and ArrowDown
- Notice that focus is lost immediately after reordering
Recording:

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
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
npm installnpm run devhttp://localhost:5173/ArrowUpandArrowDownArrowUpandArrowDownRecording:

Link to code example: https://github.com/ling1726/react-child-window-focus-repro
The current behavior
The current
getActiveElementDeepalways uses the globalwindowkeyword. Note this snippet is from the React codebasereact/packages/react-dom-bindings/src/client/ReactInputSelection.js
Lines 59 to 71 in 4f60494
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