vael-ui v0.5.7

Gestures

Layout

PullToRefresh

A pull-down gesture at the top of a scroll container that starts a refresh. Use it for feeds and lists on touch screens.

Install

import { PullToRefresh } from 'vael-ui'

Playground

  • Row 1
  • Row 2
  • Row 3
  • Row 4
  • Row 5
  • Row 6
  • Row 7
  • Row 8
Usage
<script setup lang="ts">
import { PullToRefresh } from 'vael-ui'

async function refresh() {
  await new Promise((resolve) => setTimeout(resolve, 1000))
}
</script>

<template>
  <PullToRefresh :on-refresh="refresh">
    <ul>
      <li v-for="n in 8" :key="n">Row {{ n }}</li>
    </ul>
  </PullToRefresh>
</template>

Props

NameTypeDefaultDescription
onRefreshRequired() => void | Promise<void>Runs when you release a pull past threshold. The spinner shows until its promise settles.
thresholdnumberHow far you pull, in pixels, before the refresh triggers.
maxPullnumberMaximum pull distance in pixels; the pull stops growing past it.
scrollElHTMLElement | { el: HTMLElement | null; } | nullExisting scroll container to detect pulls on. Unset, the root itself scrolls.
motionPullToRefreshMotiontrueHow it moves: its appearance ({ initial: { indicator: { opacity: 0 } } }) and its states ({ states: { refreshing: { indicator: { scale: '1.1' } } } }). false skips the settle and indicator transitions; animate the #indicator slot or exposed zoneEl yourself. The live pull still tracks your finger.
uiPartial<Record<'root' | 'zone' | 'indicator' | 'bubble' | 'label' | 'arrow', UiPartValue>>Class and style overrides for each part.

Events

No events.

Slots

NameTypeDescription
defaultanyScrollable content.
indicator{ state: PullToRefreshState; progress: number; pullDistance: number; }Replaces the default arrow, spinner and label shown in the pull zone.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
zoneElHTMLElement | nullThe pull zone above the content; it slides down with the pull.
statePullToRefreshStateCurrent phase: 'idle', 'pulling', 'ready', 'loading' or 'done'.
progressnumberPull distance as a fraction of threshold, from 0 to 1.
refresh() => Promise<void>Starts a refresh without a pull. No-op while one is already running.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

PullToRefresh: its appearance and states.

<PullToRefresh
  :motion="{ states: { pulling: { root: { scale: 1.04 } } } }"
/>
NameTypeDescription
initialexitrootindicatorSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
statespullingrefreshingSets values per part that hold while a state is on. An array is a set of keyframes that plays once as the state turns on, such as a shake on invalid.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

It has no keyboard interaction of its own.

  • The pull is touch and pointer only. Call the exposed refresh() from a button to give keyboard and screen reader users the same action.
  • The pull zone, with its arrow, spinner and label, is aria-hidden. An always-mounted role="status" region reads “Refreshing…” and then “Updated”.
  • Without scrollEl, the root scrolls, and it becomes a Tab stop while it overflows with nothing focusable inside.