Skip to content
English
Drag sort comes with Pro. Its preview shows once you unlock it.

How it works

Rows rest as filled tiles (--ds-drag-sort-bg, surface-2 by default); a lifted row turns into a raised card (--ds-drag-sort-lift-bg) with a 1.03 scale and a large soft shadow. During a drag the DOM order and container height stay fixed and everything moves by transform. Each <li> only moves; the card inside scales and casts the shadow, so movement is strictly 1:1. Passed rows make way by the lifted row's measured height plus the gap, on a soft spring. On release, FLIP finishes the move with Web Animations from the old to the new position on the same spring. Keyboard and pointer share one offset calculation, and there is no edge auto-scroll.

Use it for

  • Letting people set their own order: home shortcuts, favourites, display order of their items.
  • Reordering banners, featured slots, course chapters or FAQ entries in an admin screen.
  • Short lists that fit on one screen (a dozen items or fewer), where dragging is easiest.

Look elsewhere when

  • Long lists that need scrolling while dragging: there is no edge auto-scroll, so use move up / down / to top buttons or a number field.
  • Dragging between several lists or into a tree: this only sorts within one list.
  • Grids or horizontal layouts: only a single vertical column is supported.
  • Lists whose order is set by the system (by time or popularity): do not offer a handle that does nothing.

Usage

import { useState } from 'react'
import { DragSort } from './DragSort.jsx'

const DEFAULT = [
  { id: 'warmup', name: 'Warm-up' },
  { id: 'squats', name: 'Squats' },
  { id: 'plank', name: 'Plank' },
]

export function WorkoutOrder() {
  const [items, setItems] = useState(DEFAULT)
  return (
    <>
      <DragSort
        label="Exercise order"
        items={items}
        onChange={setItems} // called after release, only if the order changed, with the new array
        renderItem={(item, { index }) => (
          <span>
            {index + 1}. {item.name}
          </span>
        )}
      />
      <button onClick={() => setItems(DEFAULT)}>Reset</button>
    </>
  )
}

Props

PropTypeDefaultWhat it does
itemsT[] (each with a unique, stable id)—List data; each item needs a unique, stable id. Controlled: this order wins, and rows slide to their new places when it changes from outside.
onChange(nextItems) => void—Called on release (or keyboard drop) when the order really changed, with the new array. Not called on cancel or when dropped in place.
renderItem(item, state) => ReactNode—Renders a row's content (without the handle). state: { index, live while dragging; dragging, this row is lifted; sorting, some row is lifted }.
handlebooleantrueDrag only by the handle. When false, the whole row drags too (mouse after 4px, touch after a 220ms long press); the handle stays for the keyboard.
handlePosition'start' | 'end''end'Whether the handle sits at the start or the end of the row.
disabledbooleanfalseTurns sorting off.
getLabel(item, index) => stringitem label / name / titleName of each row, used for the handle's accessible name and the announcements.
labelstring—Accessible name of the list (aria-label), such as “Shortcut order”.
labelsobject—Replaces built-in screen-reader text (handle, roleDescription, instructions, lifted, moved, dropped, cancelled, item). Shallow-merged over the English defaults.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the root. Gap, radius and row background use the CSS variables --ds-drag-sort-gap, --ds-drag-sort-radius and --ds-drag-sort-bg.

Accessibility

  • The handle is a real <button>: Tab focuses it, Space or Enter lifts, Up and Down move one place, Home and End go to the ends, Space or Enter drops, Esc cancels. Losing focus while lifted drops in place.
  • Each step is announced through an aria-live region, such as “Lifted Tasks, position 1 of 4”; the text can be replaced with labels.
  • The handle has an aria-label, aria-roledescription, an aria-describedby pointing to the keyboard instructions, and aria-pressed while lifted.
  • The list is an <ol role="list"> whose DOM order always equals the visual order; focus returns to the handle after a drop.
  • On touch screens with a screen reader there are no arrow keys, so add move up / down buttons in the row that call the same onChange.
  • Reduced motion makes making way and landing instant and skips the scale-up (the raised colour and shadow stay).

Motion

No transition while dragging; the row follows 1:1. Lifting scales to 1.03 and fades the shadow in over 160ms. Making way is a 320ms translateY on a soft spring (cubic-bezier(0.34, 1.3, 0.64, 1)), and the FLIP landing uses the same 320ms spring. Over-drag damping caps at 28px; touch long press lifts after 220ms.

Add it to your project

Pro members copy a prompt and their coding agent installs the source, the same way as the free components.

DragSort.jsxdrag-sort.csstokens.cssREADME.md

Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.

Lists & layout
Arc carousel comes with Pro. Its preview shows once you unlock it.
Cylinder carousel comes with Pro. Its preview shows once you unlock it.