menumenu_openMDC

Pull To Refresh

descriptionREADMEwidgetsDemo

Material Design 3 Expressive pull-to-refresh container modeled after Android Jetpack Compose PullToRefreshBox and Flutter RefreshIndicator.

Usage

<mdc-pull-to-refresh indicator="expressive" style="height: 360px;">
    <mdc-list>
        <mdc-list-item headline="Item 1"></mdc-list-item>
        <mdc-list-item headline="Item 2"></mdc-list-item>
    </mdc-list>
</mdc-pull-to-refresh>
const ptr = document.querySelector('mdc-pull-to-refresh')
ptr.addEventListener('refresh', async () => {
    await fetchLatest()
    ptr.complete()
})

Properties

Property Attribute Type Default Description
refreshing refreshing boolean false Active refreshing state
disabled disabled boolean false Disables pull gesture
indicator indicator 'expressive' | 'circular' 'expressive' MD3E morphing indicator or classic circular spinner
variant variant 'primary' | 'secondary' | 'tertiary' | 'surface' 'primary' Color role
mode mode 'overlay' | 'push' 'overlay' Floating overlay or content-pushing layout
threshold threshold number 80 Pull distance (px) required to trigger refresh
maxPullDistance max-pull-distance number 144 Max damped pull distance (px)
dragMultiplier drag-multiplier number 0.5 Drag resistance multiplier before threshold

Indicator

Code
<mdc-pull-to-refresh indicator="expressive" style="height: 280px; border: 1px solid var(--md-sys-color-outline-variant);">
    <div style="padding: 16px;">Pull down to trigger Expressive LoadingIndicator</div>
</mdc-pull-to-refresh>

<mdc-pull-to-refresh indicator="circular" style="height: 280px; border: 1px solid var(--md-sys-color-outline-variant);">
    <div style="padding: 16px;">Pull down to trigger Classic Circular ProgressIndicator</div>
</mdc-pull-to-refresh>

Interactive

Code
<div style="display: flex; flex-direction: column; gap: 12px; max-width: 420px;">
    <div style="display: flex; align-items: center; justify-content: space-between;">
        <span id="ptr-status" style="font-size: 14px; color: var(--md-sys-color-on-surface-variant);">
            Pull down or click Trigger to refresh
        </span>
        <mdc-button id="ptr-trigger" variant="tonal"><span>Trigger</span></mdc-button>
    </div>

    <mdc-pull-to-refresh
        id="ptr-demo"
        indicator="expressive"
        style="height: 280px; border: 1px solid var(--md-sys-color-outline-variant); border-radius: 12px;"
    >
        <mdc-list id="ptr-list">
            <mdc-list-item headline="Material Design 3 Expressive" supporting-text="PullToRefreshBox physics &amp; loading indicator"></mdc-list-item>
            <mdc-list-item headline="Android Jetpack Compose" supporting-text="80dp positional threshold &amp; 0.5x drag resistance"></mdc-list-item>
            <mdc-list-item headline="Flutter RefreshIndicator" supporting-text="Supports classic elevated circular spinner"></mdc-list-item>
            <mdc-list-item headline="Overlay &amp; Push modes" supporting-text="Switchable content layout behavior"></mdc-list-item>
        </mdc-list>
    </mdc-pull-to-refresh>
</div>

<script type="module">
    const root = document.currentScript?.getRootNode?.() ?? document
    const ptr = root.getElementById?.('ptr-demo') ?? document.getElementById('ptr-demo')
    const trigger = root.getElementById?.('ptr-trigger') ?? document.getElementById('ptr-trigger')
    const status = root.getElementById?.('ptr-status') ?? document.getElementById('ptr-status')

    let count = 0
    if (ptr && status) {
        ptr.addEventListener('refresh', () => {
            count += 1
            status.textContent = `Refreshing... (#${count})`
            setTimeout(() => {
                ptr.complete()
                status.textContent = `Updated (#${count}) at ${new Date().toLocaleTimeString()}`
            }, 1400)
        })
    }

    if (trigger && ptr) {
        trigger.addEventListener('click', () => ptr.triggerRefresh())
    }
</script>

Mode

Code
<mdc-pull-to-refresh mode="overlay" style="height: 240px;">
    <div style="padding: 16px;">Overlay mode (Android PullToRefreshBox default)</div>
</mdc-pull-to-refresh>

<mdc-pull-to-refresh mode="push" style="height: 240px;">
    <div style="padding: 16px;">Push mode (content translates with pull)</div>
</mdc-pull-to-refresh>