docsy icon indicating copy to clipboard operation
docsy copied to clipboard

Scroll left toc to active entry

Open fekete-robert opened this issue 3 years ago • 5 comments

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

fekete-robert avatar May 25 '22 08:05 fekete-robert

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.

google-cla[bot] avatar May 25 '22 08:05 google-cla[bot]

@narrenfrei do you want to take a look at this?

LisaFC avatar May 30 '22 14:05 LisaFC

Hi @LisaFC and @narrenfrei, have you had a chance to review this PR?

fekete-robert avatar Sep 13 '22 08:09 fekete-robert

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

raum51 avatar Sep 13 '22 19:09 raum51

Many thanks for the comments, I'll try to fix them later this week

fekete-robert avatar Sep 14 '22 09:09 fekete-robert

@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?

fekete-robert avatar Sep 22 '22 14:09 fekete-robert