Fix autofocus handling for search widget #348

Adds logic to focus input elements with the autofocus attribute using requestAnimationFrame, ensuring proper behavior for dynamically loaded content (like the search widget) and improved compatibility with browsers like Firefox. Should fix #348
pull/885/head
Love HB 2025-11-28 11:34:24 +07:00
parent 36d5ae023f
commit d355b60901
1 changed files with 8 additions and 0 deletions

@ -203,6 +203,14 @@ function setupSearchBoxes() {
kbdElement.addEventListener("mousedown", () => {
requestAnimationFrame(() => inputElement.focus());
});
// Handle autofocus for dynamically loaded content
if (inputElement.hasAttribute("autofocus")) {
// Use requestAnimationFrame to ensure DOM is fully ready, especially for Firefox
requestAnimationFrame(() => {
inputElement.focus();
});
}
}
}