Skip to content

Commit e9eb41b

Browse files
committed
Fix mobile TOC highlight settling
1 parent a523d7a commit e9eb41b

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎website/src/components/OnThisPage.tsrx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ function activationLineFor(track: Element | null, heading: Element | null): numb
2929
const hostRect = host.getBoundingClientRect();
3030
const headingRect = heading.getBoundingClientRect();
3131
const overlapsHeading = hostRect.left < headingRect.right && hostRect.right > headingRect.left;
32-
if (overlapsHeading) return Math.max(ACTIVATION_LINE, hostRect.bottom + 12);
32+
const scrollMarginTop = Number.parseFloat(getComputedStyle(heading).scrollMarginTop) || 0;
33+
if (overlapsHeading) {
34+
return Math.max(ACTIVATION_LINE, hostRect.bottom + 12, scrollMarginTop);
35+
}
3336
return ACTIVATION_LINE;
3437
}
3538
// How long after the last scroll tick a TOC click is considered settled. Long

‎website/tests/ssr-hydration.e2e.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,12 @@ describe.sequential('website dev-SSR → hydration (real browser)', () => {
666666
null,
667667
{ timeout: 10_000 },
668668
);
669+
// The settled scroll spy must keep the chosen row active after the
670+
// click lock releases.
671+
await page.waitForTimeout(350);
672+
expect(
673+
await page.locator('.on-this-page a[href="#rspack"]').getAttribute('aria-current'),
674+
).toBe('true');
669675
const real = errors.filter((error) => !error.includes('Failed to load resource'));
670676
expect(real).toEqual([]);
671677
} finally {

0 commit comments

Comments
 (0)