Fix TOC sidebar not scrolling to active item on page load#480
Conversation
|
I don't think this fully solves the issues with the toc for all the ways the tech-docs can be structured, for example when using layouts to group items under the navigation menu. It looks fine and I have tested on a couple of sites locally which all still run and work well, have added a small comment but would ideally like to see some testing added to prevent future breakages You'll also need to up the release version and update the changelog |
|
thanks for the Review @JC-DSIT - I've added some specs, do let me know if this looks sufficient and I can look at bumping versions + changelog (I assume in a separate PR?) |
|
@d-a-v-e looks fine to me - no need to add the up version and changelog in a different PR I don't think? I'll set the checks to run now and as long as they all pass then once there's a new version it should be fine to merge in 👍 |
e1424c2 to
efb2021
Compare
Proposed changes
What changed
scrollTocToActiveItem()in_modules/in-page-navigation.jsused jQuery'sposition().topto compute whether the active TOC item needed scrolling into view.When called on initial page load (via
handleInitialLoadEvent), the browser has not yet finished layout, soposition().topreturns 0 and the function silently exits without scrolling.Two fixes:
requestAnimationFrameso layout is complete before positions are read.scrollIntoView({ block: 'nearest', inline: 'nearest' }), which is simpler and handles all edge cases.Also:
Related issue or tracking reference
Screenshots or examples (if relevant)
Before
Screen.Recording.2026-04-23.at.15.34.28.mov
After
Screen.Recording.2026-04-23.at.15.36.24.mov
Checklist
tech-docs-gem