Pull to refresh
ExpressivePull 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
Whether a refresh is running. While it is, the indicator rests at the threshold as an indeterminate loading indicator; when it turns
falsethe indicator leaves. Set ittruefrom a refresh button too, and the indicator comes in the same way. Leave it out to let a promise returned byonRefreshdrive it.How far the indicator travels before a release refreshes, px.
Turns the gesture off. A running refresh still shows its indicator.
The content: a scrolling list, grid or card collection, or a whole page. On a grid root (
gridonclassName) 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 andspace-y-*roots are exact.Ref to the root element.
Events
Called when a pull is released past the threshold. Start the refresh and set
refreshing, or return a promise: withoutrefreshing, the indicator stays until it settles.
Text
Words the pull to refresh announces, with English defaults; name them for what refreshes ("Refreshing messages"). A
LabelsProvidersets them for the whole app.
Classes for the parts:
root,layer(the sticky layer at the top) andindicator.The outer element, around the content.
The zero-height sticky layer the indicator hangs from, at the top of the area. Give it a
top-*class when a sticky app bar covers the top of a scrolling page. Its margins are the library's, so a flex root'sgap-*or a block root'sspace-y-*never moves the content. In a grid root it is a grid item, so one row gap opens above the content.The 48px circle holding the loading indicator.
Inline styles for the root element.
Classes for the root element, merged with the component's own (yours win).
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.
| Item | Status | Details |
|---|---|---|
| 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. |
Containment: contained, used with pull to refresh
BuiltConfiguration · Basic
Threshold before a refresh; reversing past it cancels
BuiltConfiguration · Threshold
Visible until the refresh completes
BuiltUse case · Feed
Refresh without relying on a gesture
BuiltUse case · Button
On the web
ExtensionThe 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
ExtensionWithout
refreshing, a promise returned byonRefreshkeeps the indicator until it settles.Announcements
ExtensionA polite live region announces the start and the end of each refresh (
labels).Arrow indicator
Not builtCompose'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
PullToRefreshis Compose'sPullToRefreshBoxwithPullToRefreshDefaults.LoadingIndicator: an 80px threshold, the half-speed drag and its resistance past the threshold (up to twice it), a 48pxprimary-containercircle 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-actionblocks vertical panning keep their drags. - Without
refreshing, a promise returned byonRefreshkeeps the indicator until it settles. There is no exported state object;data-pullinganddata-refreshingon the root expose the state.