Skip to content

Fix anchor links not scrolling in mobile hamburger menu#3121

Merged
Gerrit0 merged 2 commits into
TypeStrong:masterfrom
emmyKcodes:fix/mobile-menu-anchor-scroll
Jul 13, 2026
Merged

Fix anchor links not scrolling in mobile hamburger menu#3121
Gerrit0 merged 2 commits into
TypeStrong:masterfrom
emmyKcodes:fix/mobile-menu-anchor-scroll

Conversation

@emmyKcodes

Copy link
Copy Markdown
Contributor

What was broken

Tapping an anchor link in the mobile sidebar menu updated the URL hash but didn't scroll to the target.

Root cause

.has-menu body { overflow: hidden } is still active when the browser tries to do its native scroll-to-hash, since Toggle.ts doesn't close the menu (and lift the scroll lock) until a 250ms setTimeout later. By then the native scroll opportunity has passed.

Fix

Toggle.ts now manually calls scrollIntoView() on the target after closing the menu, instead of relying on the browser's one-shot native scroll.

Testing

Verified on [device/browser] that tapping sidebar anchors now scrolls correctly.

Fixes #3049

@emmyKcodes emmyKcodes force-pushed the fix/mobile-menu-anchor-scroll branch from 3b87f85 to 783045c Compare July 8, 2026 08:19
@emmyKcodes emmyKcodes force-pushed the fix/mobile-menu-anchor-scroll branch from 783045c to 31b42bb Compare July 8, 2026 08:47
this.setActive(false);
if (hash) {
document
.getElementById(decodeURIComponent(hash.slice(1)))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Application#scrollToHash doesn't call decodeURIComponent. In practice, I'm not sure this matters for TypeDoc's use, since all of the fragments TypeDoc generates go through the Slugger, which turns % into _... I did a bit of searching of the spec, and couldn't find anything about this being necessary - why do we decode here?

@emmyKcodes emmyKcodes Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my bad that decode wasn't necessary, it's just duplicated logic since it already exists in Application#scrollToHash.

Corrected in the latest commit

@Gerrit0 Gerrit0 merged commit 6d8c856 into TypeStrong:master Jul 13, 2026
7 checks passed
@Gerrit0

Gerrit0 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anchor links inside mobile hamburger menu do not scroll to target (URL updates, scroll does not)

2 participants