ScrollSpy: improve active feedback #41016
Open
+23
−43
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.
Motivation & Context
Current ScrollSpy behavior had some shortcomings when it comes to detecting the correct active class.
Solution
To fix this I simplified the current logic, by adding an active state for all sections and keeping track of the previous highlighted section. The current rational is to highlight the first section that is intersecting at all times.
Different logic for scrolling up or down and custom thresholds are removed due to not being needed anymore.
Note: This is a first draft, so I didn't delve deeper into all of the code that can be simplified. I would be grateful for any feedback. Thank you for your time and for this amazing project!
Changes
Scroll Behaviour:
old-scroll.mp4
new-scroll.mp4
Click Behaviour:
old-click.mp4
new-click.mp4
Type of changes
Checklist
npm run lint
)Live Previews
https://deploy-preview-41016--twbs-bootstrap.netlify.app/docs/5.3/getting-started/introduction/