Fix for smooth scrolling#1997
Merged
RobbieTheWagner merged 6 commits intoshipshapecode:masterfrom Jul 24, 2022
Merged
Conversation
When scrollTo is configured with an scrollIntoView object that has behavior set to 'smooth', the element's focus can hijack the scroll and interrupt the target from scrolling fully into view. This is particularly noticeable in browsers such as Chrome/Chromium, that implement a slower transition for the smooth scroll or when the distance to scroll is far. Configuring the element focus with the preventScroll option will ensure the smooth scroll transition will not be interrupted.
RobbieTheWagner
approved these changes
Jul 22, 2022
Member
RobbieTheWagner
left a comment
There was a problem hiding this comment.
Thank you so much for the incredibly detailed PR with description and tests. This is awesome!
Contributor
Author
|
@rwwagner90 Thank you for the approval! Taking a look at the test runs and will try get the build green shortly |
| .then((element) => calculateCenteredScrollTop(element[0])) | ||
| .then((scrollTop) => { | ||
| const plusOrMinusPx = 10; | ||
| cy.window().its('scrollY').should('be.closeTo', scrollTop, plusOrMinusPx) |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Description
Whenever a Tour's default step options is configured with
scrollTo: { behavior: 'smooth', block: 'center' }the step's target may not always scroll into the center of the viewport when stepping through the tour.An example of this behavior can be seen on Shepherd's welcome page
What causes this? Shepherd’s popover receives focus while the smooth scroll to the target is in mid-transition.
The sequence of events when a tour step is first shown:
Changes
preventScroll: trueso that it does not interrupt scrolling whenever focus shifts to the popover elementDemo
fix-smooth-scroll.mp4