-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TrapFocus] Fix error restoring focus when activeElement is null #15967
Conversation
`document.activeElement` is null in IE 11 after unmounting the element that had focus. You can see this behavior by putting the following into an html page: ``` <input id="testInput" autofocus> <script> function afterTimeout() { console.log("afterTimeout", document.activeElement); var testInput = document.getElementById("testInput"); testInput.parentNode.removeChild(testInput); // null in IE 11, body element in Chrome console.log("after removeChild", document.activeElement); } function handleLoaded() { console.log("handleLoaded", document.activeElement); setTimeout(afterTimeout); } window.addEventListener("load", handleLoaded); </script> ``` The use case where we saw this was clicking a button in one dialog which closed that dialog (unmounting the button that was just clicked and was therefore the focus element) and then opened a new dialog. Closing the new dialog then caused an error since `lastFocus.current` was null.
Details of bundle changes.Comparing: b3cace6...3192905
|
@ryancogswell Well spotted, could you update the description? I wish we can remove this defensive logic when we drop IE 11 support. It will help our future us. |
@oliviertassinari Sure. What would you like it to be? |
Maybe we could say that the whole branch logic should be removed with IE 11 support. |
We're updating to v4 in production this weekend, so one of our team members encountered this in our app during testing. For now, we're working around it by specifying |
document.activeElement
is null in IE 11 after unmounting the element that had focus.You can see this behavior by putting the following into an html page:
The use case where we saw this involved clicking a button in one dialog which closed that dialog (unmounting the button that was just clicked and was therefore the focus element) and then opened a new dialog. Closing the new dialog then caused an error since
lastFocus.current
was null.