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,8 +79,12 @@ class DisplaySearch extends Display {
onSearchInput() {
this.updateSearchButton();
const queryElementRect = this.query.getBoundingClientRect();
if (queryElementRect.top < 0 || queryElementRect.bottom > window.innerHeight) {
this.query.scrollIntoView();
}
}
onSearch(e) {
if (this.query === null) {
@ -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});
}
}