mirror of
https://github.com/go-vikunja/vikunja.git
synced 2026-03-11 17:48:44 -05:00
fix(frontend): wait for window focus before focusing quick entry input
The v-focus directive fires when the input mounts, but in the Electron quick entry window the page loads before the window is shown. This means focus() is called on a hidden window and has no effect. Now check document.hasFocus() and if the window isn't focused yet, defer the focus call to when the window receives focus.
This commit is contained in:
@@ -186,7 +186,21 @@ watchEffect(() => {
|
||||
watchEffect(() => {
|
||||
if (active.value && isQuickAddMode) {
|
||||
selectedCmd.value = commands.value.newTask
|
||||
nextTick(() => searchInput.value?.focus())
|
||||
|
||||
// The Electron window may not be visible yet when Vue mounts
|
||||
// (it's shown after did-finish-load). Try focusing now, and if
|
||||
// the window doesn't have focus yet, wait for it.
|
||||
nextTick(() => {
|
||||
if (document.hasFocus()) {
|
||||
searchInput.value?.focus()
|
||||
} else {
|
||||
const focusOnWindowReady = () => {
|
||||
searchInput.value?.focus()
|
||||
window.removeEventListener('focus', focusOnWindowReady)
|
||||
}
|
||||
window.addEventListener('focus', focusOnWindowReady)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user