scroll-into-view / scroll-into-view-if-needed

Element.scrollIntoView ponyfills for things like "if-needed" and "smooth"

Home Page:https://scroll-into-view.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Scrolling up doesn't work with scrollMode: if-needed

icd2k3 opened this issue Β· comments

πŸ‘‹ hey there,

After some investigation of an issue posted in react-scroll-into-view-if-needed here. It looks as though there is a bug with the following behavior:

  • scrolling up to a target block with scrollMode: 'if-needed'.

I setup this codesandbox to demonstrate: https://codesandbox.io/s/l4w26w2jz7
(note: it is in React, but I'd be happy to setup an html/css only one soon if it helps)

In this example, with scrollMode set to 'always', scroll to the bottom of the page and click this button at the bottom:
button

Notice that it scrolls up to the target as expected

Now, switch to 'if-needed' and notice the button does not scroll up to the target.

I'm happy to dig deeper in the near future and submit a PR if I can find the problem, but in the meantime just wanted to document it here for visibility.

Thanks for your work on this package!

Hey thanks for the detailed report! I am on the go today but I will circle back in around 10 hours and have a go at it πŸ˜„

The flaw is probably too simplistic logic here: https://github.com/stipsan/scroll-into-view-if-needed/blob/73e7d76ab7a1e678a47f3c63a0452a3e1b96f6a5/src/compute.ts#L256-L273

@icd2k3 #276 should fix it. I have tested it locally as well as on the codesandbox you shared. πŸ˜„

πŸŽ‰ This issue has been resolved in version 2.2.5 πŸŽ‰

The release is available on:

Your semantic-release bot πŸ“¦πŸš€

Sweet! Thanks for the timely fix @stipsan