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
fix: Correct modal focus behavior on macOS #18995
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @erickzhao! Overall looks good to me - I would just make your new test a little more robust by verifying the main window can regain focus once the modal is closed.
@jkleinsc Seems like calling |
Release Notes Persisted
|
I have automatically backported this PR to "4-2-x", please check out #19061 |
I have automatically backported this PR to "6-0-x", please check out #19062 |
I have automatically backported this PR to "5-0-x", please check out #19063 |
Description of Change
Fixes #18502
This PR changes the
focus
andblur
events that we emit in Electron to listen to changes in key window rather than main window. It swaps outwindowDidBecomeMain
andwindowDidResignMain
forwindowDidBecomeKey
andwindowDidResignKey
, respectively.It seems to work as intended now. Also added a new test to test this exact situation. Please let me know if there's a less convoluted way to test this specific case, since it seems like I'm listening to a very specific series of events. Test seems to be working locally on my end, and fails on a downloaded CI build from
master
. ✅Context
In our macOS code, the
NativeWindowMac::Show()
function innative_window_mac.mm
calls thisbeginSheet
function, which specifies that:For additional context, see Apple developer documentation on key and main windows here.
Fiddle: https://gist.github.com/c9c19684f6e0d23c102161fb3e86500b
cc @codebytere @deermichel
Checklist
npm test
passesRelease Notes
Notes: Fixed bug on macOS where the main window could be targeted for a
focus
event when it was disabled behind a modal.