Skip to content
v0.9.1
Components

Pull to refresh

Pull down at the top of a list to load what is new: the gesture every phone app has. The content follows your finger, an arrow turns when you have pulled far enough, and a spinner stays until your data has arrived.

A list that refreshes

Touch screens only: on a phone pull with your finger; on a computer use the Refresh button (a mouse cannot pull, and it is good for keyboard users too). Each refresh brings in a new order.

Today's orders
  • AKOrder #10430Ana Kim, 1 item2 min
  • MROrder #10429Marco Rossi, 2 items9 min
  • LFOrder #10428Lena Fischer, 3 items16 min
  • SOOrder #10427Sam Okafor, 1 item23 min
  • PNOrder #10426Priya Nair, 2 items30 min
  • DWOrder #10425Devin Williams, 1 item37 min
<div class="w-96 max-w-full">
  <div class="cluster justify-between items-center mb-2">
    <b>Today's orders</b>
    <button class="btn btn-sm" type="button" onclick="Momo.refresh('#refresh-orders')"><i class="mi mi-refresh-cw"></i> Refresh</button>
  </div>
  <div class="border rounded bg-surface overflow-auto" style="height: 19rem" data-momo-refresh id="refresh-orders">
    <ul class="list-group list-group-flush" id="refresh-list">
      <li class="list-group-item"><span class="avatar avatar-sm bg-pink">AK</span><span><b>Order #10430</b><small>Ana Kim, 1 item</small></span><small class="list-group-end">2 min</small></li>
      <li class="list-group-item"><span class="avatar avatar-sm bg-cyan">MR</span><span><b>Order #10429</b><small>Marco Rossi, 2 items</small></span><small class="list-group-end">9 min</small></li>
      <li class="list-group-item"><span class="avatar avatar-sm bg-yellow">LF</span><span><b>Order #10428</b><small>Lena Fischer, 3 items</small></span><small class="list-group-end">16 min</small></li>
      <li class="list-group-item"><span class="avatar avatar-sm bg-lime">SO</span><span><b>Order #10427</b><small>Sam Okafor, 1 item</small></span><small class="list-group-end">23 min</small></li>
      <li class="list-group-item"><span class="avatar avatar-sm bg-violet">PN</span><span><b>Order #10426</b><small>Priya Nair, 2 items</small></span><small class="list-group-end">30 min</small></li>
      <li class="list-group-item"><span class="avatar avatar-sm bg-orange">DW</span><span><b>Order #10425</b><small>Devin Williams, 1 item</small></span><small class="list-group-end">37 min</small></li>
    </ul>
  </div>
</div>
<script>
  (function () {
    var n = 10430, people = [['Helena Chavez', 'HC', 'pink'], ['Blake Howard', 'BH', 'cyan'], ['Iris Tan', 'IT', 'green'], ['Omar Haddad', 'OH', 'orange']];
    document.getElementById('refresh-orders').addEventListener('momo:refresh', function (e) {
      // your fetch() goes here; this one waits a second and adds an order
      e.detail.waitUntil(new Promise(function (done) {
        setTimeout(function () {
          var p = people[n % people.length];
          n++;
          var li = document.createElement('li');
          li.className = 'list-group-item';
          li.innerHTML = '<span class="avatar avatar-sm bg-' + p[2] + '">' + p[1] + '</span><span><b>Order #' + n + '</b><small>' + p[0] + ', 1 item</small></span><small class="list-group-end">now</small>';
          document.getElementById('refresh-list').prepend(li);
          done();
        }, 1000);
      }));
    });
  })();
</script>
<main data-momo-refresh>
  <ul class="list-group">…</ul>
</main>

<script>
  const list = document.querySelector('main');
  list.addEventListener('momo:refresh', (e) => {
    e.detail.waitUntil(loadNewOrders());   // a promise: the spinner stays until it settles
  });
</script>

Add it, step by step

  1. Put data-momo-refresh on what scrolls. If the page itself scrolls, put it on your main content. If a panel scrolls on its own (a height and overflow-auto), put it on that panel.
  2. Load in momo:refresh and hand the promise to e.detail.waitUntil(). The spinner stays while it runs, then everything slides back. Without waitUntil it finishes after a short moment.
  3. Update the list when your data arrives: add the new items, replace the old ones, whatever fits.
  4. Give computers a button that calls Momo.refresh(el): the same spinner and the same event.
list.addEventListener('momo:refresh', (e) => {
  e.detail.waitUntil(
    fetch('/api/orders?since=' + newest)
      .then((r) => r.json())
      .then((orders) => orders.forEach(addOrderOnTop))
      .catch(() => Momo.toast({ title: "Couldn't refresh", text: 'Check your connection', color: 'red' }))
  );
});
list.addEventListener('momo:refreshed', () => { /* the spinner is gone */ });

Good to know

Reference

Attribute / APIWhat it does
data-momo-refreshPull to refresh on this element (the page's content, or a panel that scrolls itself)
Event momo:refreshPulled far enough: e.detail.waitUntil(promise) keeps the spinner until it settles
Event momo:refreshedDone; everything slid back
Momo.refresh(el)Refresh from code or a button (returns a promise)
.is-pulling, .is-ready, .is-refreshingThe states, for your own styling
--refresh-pullHow far it is pulled right now (px)

Start

OverviewStart Getting startedStart CustomizeStart

Guides

AccessibilityGuides BreakpointsGuides ChangelogGuides Customize componentsGuides JavaScriptGuides MotionGuides OptimizeGuides PhonesGuides RebootGuides Right-to-left (RTL)Guides Stacking orderGuides Using Momo with AIGuides

Foundations

ColorsFoundations TypographyFoundations ProseFoundations Images & figuresFoundations CodeFoundations Lines & shadowsFoundations Dark modeFoundations

Forms

Checkbox & switchForms ComboboxForms Date pickerForms Date rangeForms Fields & labelsForms File uploadForms Floating labelsForms Number stepperForms PasswordForms PIN codeForms RatingForms SelectForms SliderForms Tag inputForms Time pickerForms ValidationForms

Components

AccordionComponents Alert & bannerComponents AvatarComponents BadgeComponents BreadcrumbComponents ButtonComponents Button groupComponents CalendarComponents CardComponents CarouselComponents ChartsComponents ChipsComponents CollapseComponents Command paletteComponents CommentsComponents Confirm dialogsComponents Cookie bannerComponents Data tableComponents Description listComponents Dialog & toastComponents DividerComponents DrawerComponents Dropdown menuComponents Empty stateComponents File managerComponents Filter & sortComponents Gallery & lightboxComponents Inbox & chatComponents Infinite scrollComponents KanbanComponents Keyboard shortcutsComponents List groupComponents MarqueeComponents Media objectComponents Nav overflowComponents Notification centerComponents PaginationComponents ProgressComponents Pull to refreshComponents SkeletonComponents SortableComponents SpinnerComponents Split viewComponents Stat cardComponents Steps & wizardComponents Swipe actionsComponents TableComponents TabsComponents TimelineComponents TogglerComponents Tooltip & popoverComponents TourComponents Tree viewComponents VideoComponents WhiteboardComponents

Layout

Announcement barLayout App shellLayout Back to topLayout Container & sectionLayout ExamplesLayout FooterLayout HeroLayout JumbotronLayout Mega menuLayout NavbarLayout Site sidebarLayout

Sections

Bento gridSections Blog cardsSections Call to actionSections Contact & newsletterSections FAQSections FeaturesSections Logo cloudSections PricingSections TeamSections TestimonialsSections

Utilities

OverviewUtilities State variantsUtilities Display & flexUtilities Grid & gapUtilities SpacingUtilities SizingUtilities TextUtilities Links & color strengthUtilities Position & overflowUtilities BackgroundsUtilities Borders & effectsUtilities Transforms & filtersUtilities InteractionsUtilities

Helpers

Fixed, sticky & frostedHelpers Hover & focusHelpers Hover revealHelpers Icon linkHelpers PrintHelpers Relative timeHelpers Screen reader textHelpers Scroll inHelpers ScrollspyHelpers Share buttonHelpers Skip linkHelpers StacksHelpers Stretched linkHelpers Theme toggleHelpers Truncated textHelpers

Page patterns

404 pagePage patterns Coming soonPage patterns Login & registerPage patterns SettingsPage patterns ProfilePage patterns CRM contactsPage patterns ProjectsPage patterns File manager pagePage patterns Billing & plansPage patterns Help centerPage patterns Mobile app screensPage patterns
↑ ↓ moveEnter openEsc close