Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions core/pfe-core/controllers/scroll-spy-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export class ScrollSpyController implements ReactiveController {
/** Has the intersection observer found an element? */
#intersected = false;

#destinationTarget: Element | null = null;

#root: ScrollSpyControllerOptions['root'];

#rootMargin?: string;
Expand Down Expand Up @@ -201,6 +203,12 @@ export class ScrollSpyController implements ReactiveController {
}

async #onIo(entries: IntersectionObserverEntry[]) {
if (this.#force && this.#destinationTarget) {
if (entries.some(e => e.target === this.#destinationTarget && e.isIntersecting)) {
this.#force = false;
this.#destinationTarget = null;
}
}
if (!this.#force) {
for (const { target, boundingClientRect, intersectionRect } of entries) {
const selector = `:is(${this.#tagNames.join(',')})[href="#${target.id}"]`;
Expand Down Expand Up @@ -244,14 +252,13 @@ export class ScrollSpyController implements ReactiveController {
public async setActive(link: EventTarget | null): Promise<void> {
this.#force = true;
this.#setActive(link);
this.#destinationTarget = this.#linkTargetMap.get(link as Element) ?? null;
let sawActive = false;
for (const child of this.#linkChildren) {
this.#markPassed(child, !sawActive);
if (child === link) {
sawActive = true;
}
}
await this.#nextIntersection();
this.#force = false;
}
}
Loading