Skip to content

Commit

Permalink
Paginator: fix focus lost when loading new section
Browse files Browse the repository at this point in the history
Also add method for setting focus on the content window
  • Loading branch information
johnfactotum committed Sep 15, 2024
1 parent c17b542 commit e6937ee
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions paginator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit e6937ee

Please sign in to comment.