focus and scroll to input only when it's needed

This commit is contained in:
siikamiika 2019-10-26 14:30:36 +03:00
parent fe8eb76928
commit 9132814ccf

View File

@ -79,7 +79,11 @@ class DisplaySearch extends Display {
onSearchInput() {
this.updateSearchButton();
this.query.scrollIntoView();
const queryElementRect = this.query.getBoundingClientRect();
if (queryElementRect.top < 0 || queryElementRect.bottom > window.innerHeight) {
this.query.scrollIntoView();
}
}
onSearch(e) {
@ -123,7 +127,7 @@ class DisplaySearch extends Display {
}
}
if (!super.onKeyDown(e) && !preventFocus) {
if (!super.onKeyDown(e) && !preventFocus && document.activeElement !== this.query) {
this.query.focus({preventScroll: true});
}
}