Fix #29 remove active class on first item in nav, when scrolled back up #56
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a small patch that fixes an issue identified in #29 where the first menu item's
active
class isn't removed when scrolling back up to content on the page before the section whose ID corresponds to that menu item.Demo of the incorrect behavior (as previously requested in #29):
scrollspy-bug-demo.mp4
In this demo, I removed the
active
class on the "Hero" menu link and changed the ID of the Hero section to something other than "hero". When scrolling past the Hero section in this demo, theactive
class is correctly added to the "Section 1" menu item; when scrolling back up to the Hero section, theactive
class is not removed.I determined that there exists a condition where the plugin finds a
0
value for a section's starting position but still returns that section as being in view because the document's scroll position is greater than 0.Additionally, I'm not familiar with TypeScript so it may be worth reviewing what few changes I made for type safety. In particular, one of my modifications changes type information to accept a null value. There may be a better way to accomplish my goal that I'm not aware of, I just needed a quick and dirty solution to be able to use this plugin properly.
Cheers for the great work, found this plugin after struggling with Bootstrap's built-in (and broken) Scrollspy plugin!