Setting Modal = true in BrowserOptions does not work #765

Open
opened 2026-01-29 16:47:59 +00:00 by claunia · 0 comments
Owner

Originally created by @lukebordonaro on GitHub (Feb 21, 2022).

  • Version: 13.5.1

  • Target: windows

If you set BrowserWindowOptions.Modal = true when creating a new BrowserWindow, the created window will not be a modal window even after setting the parent.

Consider this code:

var parent = Electron.WindowManager.BrowserWindows.First(); // assume a main window exists and this returns it
var child = await Electron.WindowManager.CreateWindowAsync(
            new BrowserWindowOptions
            {
                Show = false,
                Modal = true
            });
child.SetParentWindow(parent);

child.OnReadyToShow += () =>
{
    child.Show();
}

child.OnShow += async () =>
{
    var isModal = await child.IsModalAsync();
}

The observed behavior of the child window is that it is NOT a modal window, and you can still interact with the main window (parent). The value of isModal in the OnShow handler is false, too.

I haven't investigated this, but it's possible that for modal windows to work the parent must be set inside the BrowserWindowOptions: https://www.electronjs.org/docs/latest/api/browser-window/#modal-windows

Originally created by @lukebordonaro on GitHub (Feb 21, 2022). * **Version**: 13.5.1 * **Target**: windows If you set `BrowserWindowOptions.Modal = true` when creating a new `BrowserWindow`, the created window will not be a modal window even after setting the parent. Consider this code: ```cs var parent = Electron.WindowManager.BrowserWindows.First(); // assume a main window exists and this returns it var child = await Electron.WindowManager.CreateWindowAsync( new BrowserWindowOptions { Show = false, Modal = true }); child.SetParentWindow(parent); child.OnReadyToShow += () => { child.Show(); } child.OnShow += async () => { var isModal = await child.IsModalAsync(); } ``` The observed behavior of the child window is that it is NOT a modal window, and you can still interact with the main window (`parent`). The value of `isModal` in the `OnShow` handler is `false`, too. I haven't investigated this, but it's possible that for modal windows to work the `parent` must be set inside the `BrowserWindowOptions`: https://www.electronjs.org/docs/latest/api/browser-window/#modal-windows
claunia added the bug label 2026-01-29 16:47:59 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#765