From e6937eed15096162aa9496505ce84a0dd192c679 Mon Sep 17 00:00:00 2001 From: John Factotum <50942278+johnfactotum@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:10:14 +0800 Subject: [PATCH] Paginator: fix focus lost when loading new section Also add method for setting focus on the content window --- paginator.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/paginator.js b/paginator.js index d53bc4d..8668922 100644 --- a/paginator.js +++ b/paginator.js @@ -866,6 +866,7 @@ export class Paginator extends HTMLElement { async #display(promise) { const { index, src, anchor, onLoad, select } = await promise this.#index = index + const hasFocus = this.#view?.document?.hasFocus() if (src) { const view = this.#createView() const afterLoad = doc => { @@ -890,6 +891,7 @@ export class Paginator extends HTMLElement { } await this.scrollToAnchor((typeof anchor === 'function' ? anchor(this.#view.document) : anchor) ?? 0, select) + if (hasFocus) this.focusView() } #canGoToIndex(index) { return index >= 0 && index <= this.sections.length - 1 @@ -1006,6 +1008,9 @@ export class Paginator extends HTMLElement { // needed because the resize observer doesn't work in Firefox this.#view?.document?.fonts?.ready?.then(() => this.#view.expand()) } + focusView() { + this.#view.document.defaultView.focus() + } destroy() { this.#observer.unobserve(this) this.#view.destroy()