Skip to content

Pull to refresh

Expressive

Pull down at the top of a list or page to reload it, with a contained loading indicator that follows the pull.

import { PullToRefresh } from '@windmorph/react';

Props

PullToRefresh 10 props

  • refreshingtype boolean

    Whether a refresh is running. While it is, the indicator rests at the threshold as an indeterminate loading indicator; when it turns false the indicator leaves. Set it true from a refresh button too, and the indicator comes in the same way. Leave it out to let a promise returned by onRefresh drive it.

  • thresholdtype numberdefault 80

    How far the indicator travels before a release refreshes, px.

  • disabledtype booleandefault false

    Turns the gesture off. A running refresh still shows its indicator.

  • childrentype ReactNode

    The content: a scrolling list, grid or card collection, or a whole page. On a grid root (grid on className) the indicator's layer is a grid item, so one row gap opens above the content; put the grid on an element inside instead. Flex, block and space-y-* roots are exact.

  • reftype Ref<HTMLDivElement>

    Ref to the root element.

Events

  • onRefreshtype () => void | Promise<unknown>Required

    Called when a pull is released past the threshold. Start the refresh and set refreshing, or return a promise: without refreshing, the indicator stays until it settles.

Text

  • labelstype Partial<PullToRefreshLabels>

    Words the pull to refresh announces, with English defaults; name them for what refreshes ("Refreshing messages"). A LabelsProvider sets them for the whole app.

Also accepts the root element's HTML attributes (id, data-*, event handlers).

Spec status

Built to the M3 Expressive pull to refresh spec. Each item of its variants and configurations links to a live example; where the M3 Expressive column of the spec differs from the original M3 one, it wins.

  • Pull to refresh (loading indicator guidelines)

    Built

    Use case · Basic, Feed

  • Containment: contained, used with pull to refresh

    Built

    Configuration · Basic

  • Threshold before a refresh; reversing past it cancels

    Built

    Configuration · Threshold

  • Visible until the refresh completes

    Built

    Use case · Feed

  • Refresh without relying on a gesture

    Built

    Use case · Button

  • On the web

    Extension

    The spec says the loading indicator is used in pull to refresh on Jetpack Compose only; this brings the same behaviour to touch, mouse and pen on the web.

  • Promise-driven refreshing

    Extension

    Without refreshing, a promise returned by onRefresh keeps the indicator until it settles.

  • Announcements

    Extension

    A polite live region announces the start and the end of each refresh (labels).

  • Arrow indicator

    Not built

    Compose's older PullToRefreshDefaults.Indicator (an arrow on a circular indicator) isn't built: M3 Expressive uses the loading indicator.

Bundle size

Gzipped, as published: the component and the library code it imports. React, React Aria, Motion and the other dependencies aren't counted, and your bundler's minifier makes it smaller still. CI fails a change that grows it past its budget.

  • PullToRefresh: 15.3 kB

M3 Expressive specs

Shape
rounded-corner-full
Elevation
level0

Differences from Compose

  • PullToRefresh is Compose's PullToRefreshBox with PullToRefreshDefaults.LoadingIndicator: an 80px threshold, the half-speed drag and its resistance past the threshold (up to twice it), a 48px primary-container circle at elevation 0, a half turn back per threshold of overshoot, and a crossfade to the indeterminate indicator on the default effects spring.
  • It settles to the threshold or away on the default effects spring of the active motion scheme, which never bounces, as Compose's default spring.
  • The web has no nested scrolling, so a gesture is decided as it starts: a downward drag with everything above it at the top pulls; anything else is left to the browser for the rest of the gesture. A pull pushed back to zero hands the gesture back, and elements whose touch-action blocks vertical panning keep their drags.
  • Without refreshing, a promise returned by onRefresh keeps the indicator until it settles. There is no exported state object; data-pulling and data-refreshing on the root expose the state.