Fix autofocus sometimes not working on the search page (#1597)
This commit is contained in:
parent
e14b52ef84
commit
e444141511
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const documentFocusController = new DocumentFocusController();
|
const documentFocusController = new DocumentFocusController('#search-textbox');
|
||||||
documentFocusController.prepare();
|
documentFocusController.prepare();
|
||||||
|
|
||||||
await yomichan.prepare();
|
await yomichan.prepare();
|
||||||
|
@ -22,13 +22,17 @@
|
|||||||
* focus a dummy element inside the main content, which gives keyboard scroll focus to that element.
|
* focus a dummy element inside the main content, which gives keyboard scroll focus to that element.
|
||||||
*/
|
*/
|
||||||
class DocumentFocusController {
|
class DocumentFocusController {
|
||||||
constructor() {
|
constructor(autofocusElementSelector=null) {
|
||||||
|
this._autofocusElement = (autofocusElementSelector !== null ? document.querySelector(autofocusElementSelector) : null);
|
||||||
this._contentScrollFocusElement = document.querySelector('#content-scroll-focus');
|
this._contentScrollFocusElement = document.querySelector('#content-scroll-focus');
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare() {
|
prepare() {
|
||||||
window.addEventListener('focus', this._onWindowFocus.bind(this), false);
|
window.addEventListener('focus', this._onWindowFocus.bind(this), false);
|
||||||
this._updateFocusedElement(false);
|
this._updateFocusedElement(false);
|
||||||
|
if (this._autofocusElement !== null && document.activeElement !== this._autofocusElement) {
|
||||||
|
this._autofocusElement.focus({preventScroll: true});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blurElement(element) {
|
blurElement(element) {
|
||||||
|
Loading…
Reference in New Issue
Block a user