Skip to content
v0.9.1
Components

Sortable

Drag things into the order you want: tasks, menu items, table rows, dashboard cards. One attribute on the list. It works with a mouse, a finger and the keyboard, and tells your app the new order so you can save it.

A list with handles

Drag a row by its handle, or Tab to a handle, press Space, move with the arrows, and Space again.

  • Write the product briefToday
  • Review the new checkout
  • Order packaging
  • Plan the holiday sale
  • Reply to wholesale leads

Order: t1, t2, t3, t4, t5

<ul class="list-group w-96" id="sort-tasks" data-momo-sortable aria-label="Tasks">
  <li class="list-group-item" data-id="t1"><span class="sort-handle"></span><span class="sort-label">Write the product brief</span><span class="badge bg-violet ms-auto">Today</span></li>
  <li class="list-group-item" data-id="t2"><span class="sort-handle"></span><span class="sort-label">Review the new checkout</span></li>
  <li class="list-group-item" data-id="t3"><span class="sort-handle"></span><span class="sort-label">Order packaging</span></li>
  <li class="list-group-item" data-id="t4"><span class="sort-handle"></span><span class="sort-label">Plan the holiday sale</span></li>
  <li class="list-group-item" data-id="t5"><span class="sort-handle"></span><span class="sort-label">Reply to wholesale leads</span></li>
</ul>
<p class="text-muted text-sm mt-2" id="sort-order">Order: t1, t2, t3, t4, t5</p>
<script>
  document.getElementById('sort-tasks').addEventListener('momo:sort', function () {
    document.getElementById('sort-order').textContent = 'Order: ' + Momo.sortable(this).value().join(', ');
  });
</script>

Add it, step by step

  1. Add data-momo-sortable to the list: a ul, an ol, a .list-group, a grid of cards, or a table's tbody. Its children become draggable.
  2. Give each item a data-id so you know which is which when you save.
  3. Decide how it is grabbed. An empty <span class="sort-handle"></span> (six dots) in each item means only the handle drags: best when the item has links or buttons, and on touch it starts at once. Without handles the whole item drags; on touch you press and hold first, so the page still scrolls.
  4. Save the order in momo:sort. Say no with e.preventDefault() and the item goes back.
list.addEventListener('momo:sort', (e) => {
  const { id, fromIndex, index } = e.detail;          // 't3', 2, 0
  saveOrder(Momo.sortable(list).value());             // ['t3', 't1', 't2', 't4', 't5']
});

A grid of cards

Grids work the same. Here without handles, so the whole card drags (press and hold on touch). With the keyboard, left and right move one place, up and down a whole row.

Revenue$48,210
Orders1,284
Customers932
Refunds23
Visits9,980
Reviews4.8
<div class="grid grid-cols-2 sm:grid-cols-3 gap-3" data-momo-sortable aria-label="Dashboard cards">
  <div class="stat" data-id="revenue"><span class="stat-label">Revenue</span><span class="stat-value">$48,210</span></div>
  <div class="stat stat-violet" data-id="orders"><span class="stat-label">Orders</span><span class="stat-value">1,284</span></div>
  <div class="stat" data-id="customers"><span class="stat-label">Customers</span><span class="stat-value">932</span></div>
  <div class="stat stat-lime" data-id="refunds"><span class="stat-label">Refunds</span><span class="stat-value">23</span></div>
  <div class="stat" data-id="visits"><span class="stat-label">Visits</span><span class="stat-value">9,980</span></div>
  <div class="stat stat-yellow" data-id="reviews"><span class="stat-label">Reviews</span><span class="stat-value">4.8</span></div>
</div>

Table rows

Put data-momo-sortable on the tbody and a handle in the first cell.

MoveProductPriceStock
Linen shirt$49.00124
Canvas tote$29.00312
Wool beanie$24.0088
Leather wallet$59.0041
<div class="table-wrap">
  <table class="table">
    <thead><tr><th class="w-12"><span class="visually-hidden">Move</span></th><th>Product</th><th>Price</th><th>Stock</th></tr></thead>
    <tbody data-momo-sortable aria-label="Products">
      <tr data-id="p1"><td><span class="sort-handle"></span></td><td class="sort-label">Linen shirt</td><td>$49.00</td><td>124</td></tr>
      <tr data-id="p2"><td><span class="sort-handle"></span></td><td class="sort-label">Canvas tote</td><td>$29.00</td><td>312</td></tr>
      <tr data-id="p3"><td><span class="sort-handle"></span></td><td class="sort-label">Wool beanie</td><td>$24.00</td><td>88</td></tr>
      <tr data-id="p4"><td><span class="sort-handle"></span></td><td class="sort-label">Leather wallet</td><td>$59.00</td><td>41</td></tr>
    </tbody>
  </table>
</div>

Between lists

Give several lists the same name, data-momo-sortable="chores", and items move between them. With the keyboard, left and right move a picked-up item to the next list. e.detail.from and e.detail.to are the lists. For a full board with columns, counts and limits, see Kanban.

Today

  • Pack 12 orders
  • Call the printer
  • Update the shop banner

Later

  • Photograph the new mugs
  • Write the newsletter
<div class="grid sm:grid-cols-2 gap-4">
  <div>
    <p class="fw-bold mb-2" id="sort-today">Today</p>
    <ul class="list-group" data-momo-sortable="chores" aria-labelledby="sort-today">
      <li class="list-group-item" data-id="c1"><span class="sort-handle"></span><span class="sort-label">Pack 12 orders</span></li>
      <li class="list-group-item" data-id="c2"><span class="sort-handle"></span><span class="sort-label">Call the printer</span></li>
      <li class="list-group-item" data-id="c3"><span class="sort-handle"></span><span class="sort-label">Update the shop banner</span></li>
    </ul>
  </div>
  <div>
    <p class="fw-bold mb-2" id="sort-later">Later</p>
    <ul class="list-group" data-momo-sortable="chores" aria-labelledby="sort-later">
      <li class="list-group-item" data-id="c4"><span class="sort-handle"></span><span class="sort-label">Photograph the new mugs</span></li>
      <li class="list-group-item" data-id="c5"><span class="sort-handle"></span><span class="sort-label">Write the newsletter</span></li>
    </ul>
  </div>
</div>

Notes

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