Skip to content

v1.4.0

Compare
Choose a tag to compare
@stipsan stipsan released this 16 Nov 23:46
78973d3

Added

  • New handleScroll option allows customizing scrolling behavior.

Changed

  • Animation logic is separated from scroll calculation logic. This allows skip
    importing animation dependencies and reduces bundle sizes when you don't need
    the built in animation feature.

What this means

Take control over how the target is scrolled into view. This function is called
for each parent node that need scrolling. scrollLeft and scrollTop are
destination coordinates. The from coordinates you'll have to get yourself if you
want to animate the transition using a different library.

When using this option you likely don't need the built in animation feature. To
cut down on filesize you can do the following adjustment if you are using a
recent version of webpack or rollbar (and use ES6 imports):

-import scrollIntoViewIfNeeded from 'scroll-into-view-if-needed'
+import maybeScrollIntoView from 'scroll-into-view-if-needed/dist/calculate'
 
-scrollIntoViewIfNeeded(node)
+maybeScrollIntoView(node, {handleScroll: (parent, {scrollLeft, scrollTop}, config) => {
+  // The following is actually the default implementation
+  // if this is all you need you can skip passing this option
+  parent.scrollLeft = scrollLeft
+  parent.scrollTop = scrollTop
+}})