You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dialog is always in focus (pressing Esc closes it)
Expected behavior
Pressing Esc does not close the dialog when opened for the first time
Possible solution
This comment added with Overlay2 is exactly the root cause; the dialog's autoFocus does not work properly. (I'm not sure if this is intentionally left as is.)
// container element may be undefined between component mounting and Portal rendering
// activeElement may be undefined in some rare cases in IE
constcontainer=getRef(containerElement);
constactiveElement=getActiveElement(container);
if(container==null||activeElement==null){
return;
}
When the dialog is mounted with isOpen={true}, React 18 seems to pretty consistently mount the overlayWillOpenuseEffect and even let the bringFocusInsideOverlayrequestAnimationFrame run before rendering the Portal and container.
In our much larger application, I was also able to reproduce this with a mounted lazy Dialog, but not lazy={false}, so this might depend on render performance fluctuations or something. This also affects all of React 18, not just StrictMode.
This is quite a minor annoyance, but might need delaying the auto-focus to a later callback.
The text was updated successfully, but these errors were encountered:
PetrusAsikainen
changed the title
Dialog (or Overlay2) autoFocus fails when mounted as open in React 18
Overlay2 autoFocus fails when mounted as open in React 18
Jul 9, 2024
Environment
Code Sandbox
https://codesandbox.io/p/devbox/long-tree-htjf9p
Steps to reproduce
Actual behavior
Dialog is always in focus (pressing Esc closes it)
Expected behavior
Pressing Esc does not close the dialog when opened for the first time
Possible solution
This comment added with Overlay2 is exactly the root cause; the dialog's
autoFocus
does not work properly. (I'm not sure if this is intentionally left as is.)blueprint/packages/core/src/components/overlay2/overlay2.tsx
Lines 128 to 135 in 2dc48d8
When the dialog is mounted with
isOpen={true}
, React 18 seems to pretty consistently mount theoverlayWillOpen
useEffect
and even let thebringFocusInsideOverlay
requestAnimationFrame
run before rendering thePortal
and container.In our much larger application, I was also able to reproduce this with a mounted
lazy
Dialog, but notlazy={false}
, so this might depend on render performance fluctuations or something. This also affects all of React 18, not just StrictMode.This is quite a minor annoyance, but might need delaying the auto-focus to a later callback.
The text was updated successfully, but these errors were encountered: