Skip to content
synccn

Sortable List

Drag to reorder, with Alt+arrow keyboard support.

  • 1. Design reviewMichael
    Today
  • 2. Ship pricing pageRiley
    Tomorrow
  • 3. Write release notesJayden
    Friday
  • 4. Plan next sprintMichael
    Next week

Drag the handles, or focus one and press Alt + ↑/↓.

Installation

$ pnpm dlx shadcn@latest add @synccn/sortable-list

First time in this project? Connect synccn with one command.

Usage

import { SortableList } from "@/components/ui/sortable-list";<SortableList items={items} onChange={setItems} renderItem={(it) => …} />

API reference

Generated from the component's TypeScript types, so it always matches the code.

SortableList

Drag to reorder (mouse or touch), or focus a handle and use Alt+Up / Alt+Down. items: [{ id, ... }]; renderItem(item) returns the row content.

  • items
    T[]

    Controlled items.

  • defaultItems
    T[]

    Initial items when uncontrolled.

  • onChange
    (items: T[]) => void

    Called with the new order.

  • renderItemrequired
    (item: T, index: number) => React.ReactNode

    Renders a row's content.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseControllable (works controlled or uncontrolled)

npm packages

Keyboard

  • ↑or↓Move the focused item up or down

Accessibility

  • Every move is announced through a live region, so screen reader users hear the new position.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA attributes: aria-label, aria-live
  • Keys handled: ArrowUp, ArrowDown
  • Includes text only screen readers hear
  • Announces changes to screen readers