prevent auto-scroll when focus is set inside header panels

This commit is contained in:
Joe 2021-11-05 10:35:48 +08:00 committed by Robin Ward
parent 8586088b87
commit f444e3e3f7
1 changed files with 9 additions and 3 deletions

View File

@ -484,7 +484,9 @@ export default createWidget("header", {
// auto focus on first button in dropdown
schedule("afterRender", () =>
document.querySelector(".user-menu button")?.focus()
document.querySelector(".user-menu button")?.focus({
preventScroll: true,
})
);
},
@ -494,7 +496,9 @@ export default createWidget("header", {
// auto focus on first link in dropdown
schedule("afterRender", () => {
document.querySelector(".hamburger-panel .menu-links a")?.focus();
document.querySelector(".hamburger-panel .menu-links a")?.focus({
preventScroll: true,
});
});
},
@ -624,7 +628,9 @@ export default createWidget("header", {
if (this.state.searchVisible) {
schedule("afterRender", () => {
const searchInput = document.querySelector("#search-term");
searchInput.focus();
searchInput.focus({
preventScroll: true,
});
searchInput.select();
});
}