changed scrollIntoView to target all scrollable parents #55
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.
I ran into an issue working with this polyfill's scrollIntoView on a site (this one) that has a body set to
height: 100%
with all of the page's content existing in a scrollable child div. Any direct children of that div would scroll as expected, but if the target of the scroll was nested within another scrollable div (think the 'hello!' section of your example) the main-page div wouldn't scroll down to it. This was different behavior from the default scrollIntoView method, which would scroll to the element in Firefox.Changing the if statement in the polyfill to a while loop fixed this for me, and improves how it works in other cases of nested scrollable divs.
For what it's worth, this doesn't seem to to be quite how the default method works. On the modified home page, Firefox will 1) scroll each div until the target element is at the top of its parent---unless the target element is already at the top of it's parent, in which case do the same to the next scrollable parent, etc.---and 2) also scroll the body down so the top of the viewport is aligned with the element. This is almost what the polyfill does, but not quite, as multiple clicks in Firefox will eventually bring the element to where it wants to be, whereas multiple clicks with the polyfill will not.
I feel like the while loop method is the most flexible option, as it works no matter which element is functioning as the page body, and brings the element into view with one click. But I don't know what the word is on having polyfills deviate from the default behavior, even if they end up performing slightly better. It's also is a pretty unlikely scenario where it makes a real difference (who nests multiple scrollable divs?) but thought I'd share this sorta-solution rather than opening an issue. :)