rfcs icon indicating copy to clipboard operation
rfcs copied to clipboard

VueRouter - Allow scrolling other than window

Open phouri opened this issue 5 years ago • 6 comments

Rendered

phouri avatar May 23 '19 12:05 phouri

Would using scrollIntoView be an option as a way to solve the first drawback about old browser quirks?

pimlie avatar Jun 26 '19 09:06 pimlie

ScrollIntoView does something else afaik - it scrolls the parent of a child to get the child into view, and does not scroll the element itself.

phouri avatar Jun 26 '19 09:06 phouri

This should work:

if (isObject && typeof shouldScroll.selector === 'string') {
    const el = document.querySelector(shouldScroll.selector)
    if (el) {
      el.scrollIntoView()
    }

we'd only need to add additional logic for isPop

pimlie avatar Jun 26 '19 09:06 pimlie

It's not just scrolling into view - it's keeping the last position, scrolling element can be huge - thousands of pixels, scrolling to the top of it (or center or any other option) - is not the required behavior, it should be where it was before navigation.

phouri avatar Jun 26 '19 09:06 phouri

Hmm, yes. Isnt that actually managed by saveScrollPosition anyway? The position calculated in scrollToPosition doesnt seem to be used for that.

pimlie avatar Jun 26 '19 09:06 pimlie

save scroll position saves it only from the window, which is in some cases not the scroller.

Check out my draft PR for a full example - it saves the new position and uses it on the new element.

phouri avatar Jun 26 '19 09:06 phouri