Skip to content

Commit

Permalink
Paginator: fix anchoring in scrolled mode
Browse files Browse the repository at this point in the history
Anchoring triggers the `scroll` event, which in scrolled mode causes
`#afterScroll()` to be called again with the reason `scroll`, which
shouldn't happen as it's just anchoring, not scrolling.
  • Loading branch information
johnfactotum committed Aug 25, 2023
1 parent df95960 commit ad25f6b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion paginator.js
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ export class Paginator extends HTMLElement {
#margin = 0
#index = -1
#anchor = 0 // anchor view to a fraction (0-1), Range, or Element
#justAnchored = false
#locked = false // while true, prevent any further navigation
#styles
#styleMap = new WeakMap()
Expand Down Expand Up @@ -476,7 +477,10 @@ export class Paginator extends HTMLElement {

this.#observer.observe(this.#container)
this.#container.addEventListener('scroll', debounce(() => {
if (this.scrolled) this.#afterScroll('scroll')
if (this.scrolled) {
if (this.#justAnchored) this.#justAnchored = false
else this.#afterScroll('scroll')
}
}, 250))

const opts = { passive: false }
Expand Down Expand Up @@ -805,6 +809,7 @@ export class Paginator extends HTMLElement {
const range = this.#getVisibleRange()
// don't set new anchor if relocation was to scroll to anchor
if (reason !== 'anchor') this.#anchor = range
else this.#justAnchored = true

const index = this.#index
const detail = { reason, range, index }
Expand Down

0 comments on commit ad25f6b

Please sign in to comment.