All components

MotionPager

Swipeable pages from data: onboarding, carousels and tab panels.

WebReact NativeSelection and paging

Try it

Preparing the example…

Shortest usage

Onboarding.jsx
<MotionPager
  items={slides}
  index={page}
  onIndexChange={setPage}
  gap={16}
  renderItem={(slide) => <Slide slide={slide} />}
/>;

What it handles for you

  • Pages follow swipes and mouse drags, resist past the ends and settle with your release speed.
  • A flick always turns a page, and one gesture never turns more than one.
  • Horizontal trackpad scrolling turns pages too, and its momentum tail is ignored.
  • Arrow keys, Home and End work when the pager is focused, and vertical scrolling keeps working.
  • Pages other than the active one are inert.

Use it for

  • An onboarding flow.
  • A photo carousel.
  • Swipeable tab panels paired with MotionHighlight.

Props

PropTypeDefaultDescription
itemsreadonly T[]—requiredYour data array.
indexnumberThe page shown. Leave it out to let the pager keep its own.
defaultIndexnumber0Starting page when index is not controlled.
onIndexChange(index, item) => voidRuns with the index and item as soon as a swipe, key or wheel gesture settles.
getKey(item) => string | numberitem.idReturns a unique, stable key for an item. Defaults to item.id, or the item itself for strings and numbers.
renderItem(item, { index, active }) => ReactNodeitem.labelDraws a page; receives its index and whether it is active.
gapnumber0Space between pages in pixels.
itemClassNamestringClass for each item element; itemStyle sets its inline style.
transitionTransitionspringA timing curve { duration, easing } or a spring { tempo: 'spring', spring }. Springs keep their momentum when interrupted.

Other props go to the rendered element, so className, style and event handlers work as usual.

Web and React Native

index can be controlled (onIndexChange(index, item) reports every settle) or left to the pager with defaultIndex.

The same component and props work on React Native.

Used in these examples

Search

Type to search the documentation.