ScrollSpy: improve active feedback#41016
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 |
Manchmal1
left a comment
There was a problem hiding this comment.
Danke für die Mühe und ganze Arbeit 👍👍
|
Thanks for taking a stab at finally fixing this! In case it’s helpful to cross-reference, there’s a long thread at #36431 discussing various aspects of the current buggy behavior. |
|
Ost es aktiv was muss ich machen um es zu aktivieren das es auf meinem zandy oder tv läuft |
|
@julien-deramond Hey! I've pushed some changes and separated them into commits for easier review. When you have a moment, PTAL. @codyrobbins Thanks for linking the issue! Would you mind testing this version and sharing your thoughts on it? I found the wrong |
|
Hi. Will this close #36431? Or is it an offshoot of it, which doesn't fix everything? |
For me it fixed all of my problems, but I will not make any assumptions. Feedback always welcome! |
|
Hi @julien-deramond and @guilhas07, What are the remaining tasks for this PR? Please let me know if there’s any way I can help—I'm dependent on this fix. 🙂 Edit: Also, I noticed that this is going to target #36431. This was a "nice to have" in 5.3.4, and since it is now done, is there a plan to add this to an upcoming 5.4 project or any other bugfix version? |
|
@dgatla At the moment I'm unfortunately swamped with both work commitments and personal matters. Aside from bumping dependencies, I won’t be very available until early December. Around that time, I’ll need to do a first overall review of the v6 draft branch. For this specific PR, if anyone is able to help, the most valuable contribution would be to thoroughly test the new implementation: try to break the component in as many usage scenarios as you can think of. This will help us understand whether the change is a real improvement, determine the limitations of this improvement, and also determine if it could be released as a patch, minor, or major version, depending on any breaking changes. Thanks to everyone involved in this effort. |
|
Put some time in with Claude to see if we can get a rewrite in for v6—this wouldn't be able to land in v5 unfortunately. See #42557 for that. Happy to review any feedback there, or adjust as needed. Let me know what you think! In the mean time, I'll leave this open, but I don't expect to see it merged at this point for v5. |
I have already rewrote the component, keeping the basic functionality. I rewrote all the tests and spent a week on it (some tests were just for show), but they didn't review this commit because there were too many changes. However, it is necessary to rewrite the module. Maybe we should give this commit a chance? Or at least lean on it, or do you see it somehow differently? #41914 |


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.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/