Moey Icons
No results. Try “dialog”, “dark” or “grid”.
Moey extras

Swipe actions

Swipe a row to show its buttons — archive, delete, mark as read — the way mail and messaging apps do. A long swipe does the main action straight away. Scrolling up and down still works, and every action is a real button, so nothing depends on the gesture.

Drag a row sideways with the mouse (or swipe on a touch screen): left for Archive / Delete, right for Read. Drag far to the left to delete in one go.

<div class="swipe-item" data-moey-swipe data-id="m1">
  <div class="swipe-content">
    <a class="list-group-item list-group-item-action" href="#m1">
      <span class="avatar avatar-green avatar-subtle">AK</span>
      <div class="list-group-content"><div class="list-group-title">Ana Kim</div><div class="list-group-detail">Order #10421 — new address</div></div>
      <span class="list-group-meta">9:41</span>
    </a>
  </div>
  <div class="swipe-start">
    <button class="swipe-action theme-blue" data-act="read"><i class="mi mi-mail-open"></i>Read</button>
  </div>
  <div class="swipe-end">
    <button class="swipe-action theme-amber" data-act="archive"><i class="mi mi-archive"></i>Archive</button>
    <button class="swipe-action theme-red" data-act="delete" data-moey-swipe-full><i class="mi mi-trash-2"></i>Delete</button>
  </div>
</div>

On a phone

Try it with your finger (or the mouse) in a real phone-sized page:

Swipe a message

Add it, step by step

  1. Wrap the row in <div class="swipe-item" data-moey-swipe> and put the row itself in .swipe-content. The row can be anything — a list group item, a card, a table-like line.
  2. Add the buttons. .swipe-end holds the ones shown by swiping toward the start (← in left-to-right languages — the usual place for Archive and Delete); .swipe-start the ones shown by swiping toward the end (→ — Read, Pin). One side is fine.
  3. Color them with a theme-* class (theme-red for Delete, theme-amber for Archive, theme-blue for Read). They get the strong shade with readable text.
  4. Pick the long-swipe action with data-moey-swipe-full — usually the outermost button. A swipe past 60% of the row presses it.
  5. Handle the buttons like any button — a click listener. Moey closes the row afterwards; removing it is up to you (below).

Handling the actions

A delegated click listener on the list is all you need. Here a deleted row folds away and a toast says what happened:

list.addEventListener('click', (e) => {
  const button = e.target.closest('.swipe-action');
  if (!button) return;
  const row = button.closest('.swipe-item');
  if (button.dataset.act === 'delete') {
    row.style.height = row.offsetHeight + 'px';
    row.classList.add('is-leaving');                       // height and opacity animate
    requestAnimationFrame(() => { row.style.height = '0px'; row.style.opacity = '0'; });
    setTimeout(() => row.remove(), 260);
    deleteMessage(row.dataset.id);
    Moey.toast({ message: 'Deleted' });
  }
});

// Ask first after a long swipe? moey:swipe-full is cancelable:
list.addEventListener('moey:swipe-full', (e) => {
  if (!confirm('Delete this message?')) e.preventDefault();   // the row slides back
});

One side only

Invoice #2041.pdf
212 KB
<div class="swipe-item" data-moey-swipe>
  <div class="swipe-content">…</div>
  <div class="swipe-end">
    <button class="swipe-action theme-red" data-moey-swipe-full><i class="mi mi-trash-2"></i>Remove</button>
  </div>
</div>

Without swiping

  • The actions are real buttons in the page: Tab to one and its side opens; Esc or tabbing away closes it.
  • Screen readers read them as buttons after the row ("Archive", "Delete") — no gesture needed.
  • On a desktop, a mouse drag works the same as a finger; you can also offer the same actions in a menu.
  • Only clearly sideways gestures move a row — up and down always scrolls.

Reference

Class / attributeWhat it does
.swipe-item[data-moey-swipe]The row that can be swiped (--mo-swipe-bg: its background)
.swipe-contentWhat slides: the row itself
.swipe-start · .swipe-endThe buttons shown by swiping toward the end (→) · toward the start (←); they flip in right-to-left
.swipe-action + theme-*A button: icon on top, short label, in the theme's strong color
data-moey-swipe-fullPressed by a long swipe (past 60% of the row)
Events moey:swipe · moey:swipe-fullA row opened (detail: { side }) · a long swipe is about to press its action (cancelable, detail: { action, side })
Moey.swipe(item){ open('start' | 'end'), close() }