mirror of
https://github.com/john-okeefe/foliate-js.git
synced 2026-09-09 11:29:14 -04:00
Paginator: fix focus lost when loading new section
Also add method for setting focus on the content window
This commit is contained in:
@@ -866,6 +866,7 @@ export class Paginator extends HTMLElement {
|
|||||||
async #display(promise) {
|
async #display(promise) {
|
||||||
const { index, src, anchor, onLoad, select } = await promise
|
const { index, src, anchor, onLoad, select } = await promise
|
||||||
this.#index = index
|
this.#index = index
|
||||||
|
const hasFocus = this.#view?.document?.hasFocus()
|
||||||
if (src) {
|
if (src) {
|
||||||
const view = this.#createView()
|
const view = this.#createView()
|
||||||
const afterLoad = doc => {
|
const afterLoad = doc => {
|
||||||
@@ -890,6 +891,7 @@ export class Paginator extends HTMLElement {
|
|||||||
}
|
}
|
||||||
await this.scrollToAnchor((typeof anchor === 'function'
|
await this.scrollToAnchor((typeof anchor === 'function'
|
||||||
? anchor(this.#view.document) : anchor) ?? 0, select)
|
? anchor(this.#view.document) : anchor) ?? 0, select)
|
||||||
|
if (hasFocus) this.focusView()
|
||||||
}
|
}
|
||||||
#canGoToIndex(index) {
|
#canGoToIndex(index) {
|
||||||
return index >= 0 && index <= this.sections.length - 1
|
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
|
// needed because the resize observer doesn't work in Firefox
|
||||||
this.#view?.document?.fonts?.ready?.then(() => this.#view.expand())
|
this.#view?.document?.fonts?.ready?.then(() => this.#view.expand())
|
||||||
}
|
}
|
||||||
|
focusView() {
|
||||||
|
this.#view.document.defaultView.focus()
|
||||||
|
}
|
||||||
destroy() {
|
destroy() {
|
||||||
this.#observer.unobserve(this)
|
this.#observer.unobserve(this)
|
||||||
this.#view.destroy()
|
this.#view.destroy()
|
||||||
|
|||||||
Reference in New Issue
Block a user