mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: Correct modal focus behavior on macOS (#18995)
Fixes #18502 This PR changes the focus and blur events that we emit in Electron to listen to changes in key window rather than main window. It swaps out windowDidBecomeMain and windowDidResignMain for windowDidBecomeKey and windowDidResignKey, respectively.
This commit is contained in:
@@ -88,11 +88,11 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
|
||||
return frame;
|
||||
}
|
||||
|
||||
- (void)windowDidBecomeMain:(NSNotification*)notification {
|
||||
- (void)windowDidBecomeKey:(NSNotification*)notification {
|
||||
shell_->NotifyWindowFocus();
|
||||
}
|
||||
|
||||
- (void)windowDidResignMain:(NSNotification*)notification {
|
||||
- (void)windowDidResignKey:(NSNotification*)notification {
|
||||
shell_->NotifyWindowBlur();
|
||||
}
|
||||
|
||||
|
||||
@@ -1637,6 +1637,34 @@ describe('BrowserWindow module', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('focus event', () => {
|
||||
it('should not emit if focusing on a main window with a modal open', (done) => {
|
||||
const childWindowClosed = false
|
||||
const child = new BrowserWindow({
|
||||
parent: w,
|
||||
modal: true,
|
||||
show: false
|
||||
})
|
||||
|
||||
child.once('ready-to-show', () => {
|
||||
child.show()
|
||||
})
|
||||
|
||||
child.on('show', () => {
|
||||
w.once('focus', () => {
|
||||
expect(child.isDestroyed()).to.equal(true)
|
||||
done()
|
||||
})
|
||||
w.focus() // this should not trigger the above listener
|
||||
child.close()
|
||||
})
|
||||
|
||||
// act
|
||||
child.loadURL(server.url)
|
||||
w.show()
|
||||
})
|
||||
})
|
||||
|
||||
describe('sheet-begin event', () => {
|
||||
let sheet = null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user