Skip to main content

Overview

The Block DnD components provide drag-and-drop functionality for reordering blocks in your editor. Built on top of @dnd-kit, it integrates seamlessly with the renderBlock API to keep DnD logic outside the core editor.
Block Drag and Drop in action

Features

  • @dnd-kit powered — industry-standard drag and drop library
  • Multi-block selection — drag multiple selected blocks at once
  • Visual feedback — drop indicators and drag overlays
  • Accessible — keyboard support built-in
  • Customizable — style drag handles and drop indicators
  • Non-invasive — uses renderBlock API, no core editor changes

Installation

The @yoopta/ui package includes @dnd-kit as a dependency.

Quick Start

How It Works

The Block DnD system consists of three main parts:
  1. BlockDndContext — Wraps the editor, provides DnD context and handles block reordering
  2. SortableBlock — Wrapper for each block that makes it sortable. When using DragHandle, set useDragHandle={true} to prevent the entire block from being draggable
  3. DragHandle — The draggable trigger element. Must be used with SortableBlock that has useDragHandle={true}
The renderBlock prop on YooptaEditor allows you to wrap each block with DnD components without modifying the core editor. Important: When using DragHandle, you must set useDragHandle={true} on SortableBlock. This ensures that drag listeners are only applied to the handle, not the entire block.

API Reference

BlockDndContext

The root provider that wraps your editor and handles drag events.
Props:

SortableBlock

Wrapper component that makes a block sortable.
Props:

DragHandle

The draggable trigger component. Users drag this to move blocks.
Props:

useBlockDnd

Hook for accessing DnD state and utilities.
Returns:

useBlockDndContext

Hook to access the DnD context value directly.

getOrderedBlockIds

Utility function to get block IDs sorted by their order.

Examples

Basic Setup

With FloatingBlockActions

Integrate DnD with the existing FloatingBlockActions component:

Multi-Block Drag

When blocks are selected (via Shift+Click or SelectionBox), dragging one will move all selected blocks:

Read-Only Mode

Disable DnD in read-only mode:

Styling

CSS Variables

Custom Styles

The renderBlock API

The renderBlock prop on YooptaEditor is the key to integrating DnD without modifying the core editor.
This pattern allows you to:
  • Add DnD support
  • Add custom block wrappers
  • Implement block-level features without forking the editor

Best Practices

Always wrap renderBlock in useCallback to prevent unnecessary re-renders:
The context must wrap the entire editor:
Disable drag handles and sorting in read-only mode:

TypeScript

Full type definitions are exported:

FloatingBlockActions

Combine with floating actions for a complete block UI

SelectionBox

Multi-select blocks for batch operations