docsy
docsy copied to clipboard
Scroll left toc to active entry
Useful when the left-side toc is longer than the screen. Fixes https://github.com/google/docsy/issues/348 and https://github.com/google/docsy/issues/257
This is an update of the original patch of narrenfrei
Notes:
- It seems that on Firefox there is a side-effect of using https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView that causes the page to scroll its main content even if it's not needed. I haven't seen this problem in Chrome and Safari
- It might be better to use https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoViewIfNeeded but that's not yet supported in every browser
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
View this failed invocation of the CLA check for more information.
For the most up to date status, view the checks section at the bottom of the pull request.
@narrenfrei do you want to take a look at this?
Hi @LisaFC and @narrenfrei, have you had a chance to review this PR?
I think in the netlify preview the functionality doesn't work, because the sample page ist built with the cached sidebar sidebar_cache_limit: 10.
Also the script that adapts the sidebar menu when the sidebar cache is use have to set the id of the span to td-sidebar-nav-active-item. Actually only a class get added.
https://github.com/google/docsy/blob/64883607d575921291ec09485dde77e61698d828/layouts/partials/sidebar.html#L11
Many thanks for the comments, I'll try to fix them later this week
@raum51 : I've added a line to add the id to the span, but if the cache limit is low, the scrolling doesn't work for some reason. Any ideas?