mirror of
https://github.com/esphome/esphome-docs.git
synced 2025-01-24 22:02:04 +01:00
Be less aggressive in maintaining focus on search box (#4395)
* Be less aggressive in maintaining focus on search box * Also focus when clear clicked
This commit is contained in:
parent
7ce07b9512
commit
542a91a42d
@ -157,10 +157,20 @@
|
||||
resizeTarget();
|
||||
}
|
||||
|
||||
function search_focus() {
|
||||
const input_field = document.getElementById("pfmod-input-0");
|
||||
if (input_field) {
|
||||
requestAnimationFrame(() => input_field.focus());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function hideTargets() {
|
||||
if (target.style.display !== "none") {
|
||||
target.style.display = "none";
|
||||
document.removeEventListener('click', clickCallback);
|
||||
// keep focus on search box after clicking on search result
|
||||
search_focus();
|
||||
}
|
||||
}
|
||||
|
||||
@ -200,14 +210,12 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
const input_field = document.getElementById("pfmod-input-0");
|
||||
if (input_field) {
|
||||
input_field.focus({preventScroll: true});
|
||||
input_field.addEventListener("blur", () => {
|
||||
requestAnimationFrame(() => {
|
||||
input_field.focus({preventScroll: true});
|
||||
});
|
||||
})
|
||||
// focus the search field on page load.
|
||||
search_focus();
|
||||
// focus when clicking on clear button
|
||||
const clears = document.getElementsByClassName("pagefind-modular-list-clear");
|
||||
for (let i = 0; i !== clears.length; i++) {
|
||||
clears[i].addEventListener("click", search_focus);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user