-
-
Notifications
You must be signed in to change notification settings - Fork 78.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ScrollSpy: improve active feedback #41016
base: main
Are you sure you want to change the base?
Conversation
Was muß ich machen um die auf dem Fernseher zu sehen bitte |
Sorry for the delay, @guilhas07, and thank you for taking the time to work on this PR!
To wrap up, I think this PR has potential, but we need to address these edge cases. Once finalized, it would be great to add strict unit tests to enforce the new behavior. These tests could also act as documentation for the expected behavior, helping prevent regressions in the future. Edit: be careful, the tests fail right now. You can run Anyone interested in this topic, feel free to jump in and share your feedback! (/cc @twbs/js-review, you have more expertise on this than I do). (Note for us, maintainers: if this PR ends up being the main one to fix Scrollspy issues, let's add the references of all the issues related to the Scrollspy) |
First of all thank you for your feedback!
Thank you!
I'm afraid as you already mentioned that is hard to do because technically there are two elements fully shown.
Fixed.
Also fixed but this led me to change the current implementation.
I'm looking into it. I've modified some tests to align with the new behavior, and I will try to come up with new ones (if you have any suggestions, I'm all ears). Changes:My previous implementation only considered |
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 areis 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!
Edit: My previous implementation only considered header elements, which are small due to not wrapping the text in their section. However, when using entire div elements, it became impossible to activate the next element because, in many cases, two elements would be visible simultaneously. To address this, I now activate the element with the larger intersection ratio. To achieve this, I keep track of each element's intersection ratio and have increased the thresholds to recalculate the intersection ratios at every 10% increment.
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/