diff options
author | siikamiika <siikamiika@users.noreply.github.com> | 2019-10-26 14:30:36 +0300 |
---|---|---|
committer | siikamiika <siikamiika@users.noreply.github.com> | 2019-10-26 14:30:36 +0300 |
commit | 9132814ccf15ec2d1272c14e4840f4affad94706 (patch) | |
tree | 93397593c8e3a72befd3b979ac02d95d08f9f682 /ext | |
parent | fe8eb76928de8ce72689b6ae3eb3a90c626c3720 (diff) |
focus and scroll to input only when it's needed
Diffstat (limited to 'ext')
-rw-r--r-- | ext/bg/js/search.js | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/ext/bg/js/search.js b/ext/bg/js/search.js index d74998d6..1a6822f6 100644 --- a/ext/bg/js/search.js +++ b/ext/bg/js/search.js @@ -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}); } } |