Sortable

A composable drag-and-drop primitive for reordering lists and item collections.

Installation

pnpm add @notion-kit/ui

Anatomy

<Sortable.Root>
  <Sortable.List>
    <Sortable.Item>
      <Sortable.Handle />
    </Sortable.Item>
  </Sortable.List>
  <Sortable.Overlay />
</Sortable.Root>

Examples


Use getSortableItemsAfterDrag in onDragEnd to update ordered state after a successful drop.

API Reference

Sortable.Root

Wraps DragDropProvider and provides orientation, disabled state, sensors, and default movement modifiers to sortable children.

PropTypeDefaultDescription
orientation"horizontal" | "vertical""vertical"Axis used by default list styling and drag restrictions.
disabledbooleanfalseDisables sortable items inside the root.
sensorsDragDropProvider["sensors"]-Custom dnd-kit sensors. Defaults to pointer/touch sensors.

Sortable.List

Renders the sortable item container. Accepts standard <div> props and Base UI render composition props.

PropTypeDefaultDescription
orientation"horizontal" | "vertical"-Overrides the root orientation for this list.
renderReactElement-Replaces the default <div> while preserving list props.

Sortable.Item

Registers one draggable item. Accepts dnd-kit sortable options in addition to render composition props.

PropTypeDefaultDescription
id*UniqueIdentifier-Stable item id used by dnd-kit.
index*number-Current item index in its list or group.
groupUniqueIdentifier-Optional group id for grouped sortable layouts.
render(state) => ReactNode-Custom item render with drag/drop state.

Sortable.Handle

Button used as the drag handle for the nearest Sortable.Item. It must be rendered inside a sortable item.

Sortable.Overlay

Renders dnd-kit's DragOverlay in a portal. Use it when you need a custom drag preview.

PropTypeDefaultDescription
containerElement | DocumentFragmentdocument.bodyPortal target for the drag overlay.
dropAnimationDragOverlay["dropAnimation"]nullDrop animation configuration.

getSortableItemsAfterDrag

Moves an array after a drag end event and returns the original array when the operation was canceled.

const nextItems = getSortableItemsAfterDrag(items, event);
ParameterTypeDescription
itemsUniqueIdentifier[] | { id: UniqueIdentifier }[]Ordered array to move.
eventDragEndEventDrag end event from Sortable.Root.

type SortableItemState

PropTypeDescription
draggingbooleanWhether the item is actively dragging.
droppingbooleanWhether the item is completing a drop.
dragSourcebooleanWhether the item is the drag source.
dropTargetbooleanWhether the item is the active target.