Issue
So far I build a simple Electron application. My problem is the input.focus()
is not working on displaying an alert box. I tried to solve the problem, and I came up with a solution: when I minimize and maximize the window, the input.focus()
is working well. So when I try to show an alert box, the input.focus()
isn't working, except minimize and maximizing. I try to open the code in Chrome, and all functionalities are working very well, so the problem is in the Electron renderer.
Before minimizing and maximizing the window
After minimizing and maximizing the window
My Electron renderer
const path = require("path");
const { app, BrowserWindow } = require("electron");
const createWindow = () => {
const win = new BrowserWindow({
width: 780,
height: 600,
minWidth: 780,
minHeight: 600,
icon: path.join(__dirname, "assets/favicon.ico"),
webPreferences: {},
});
win.maximize();
// win.removeMenu();
win.loadFile("index.html");
};
app.whenReady().then(() => {
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0)
createWindow();
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin")
app.quit();
});
Solution
The Input focus will lose if the app window not focused.
When you minimize and maximize the app window the input focus come back.
And When you send alert box the alert open in another window so the main app window blur and its input focus blur.
Answered By - Philo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.