Convert Figma logo to code with AI

atlassian logoreact-beautiful-dnd

Beautiful and accessible drag and drop for lists with React

33,472
2,598
33,472
642

Top Related Projects

20,973

Drag and Drop for React

A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list✌️

29,843

Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.

10,837

Infinite responsive, sortable, filterable and draggable layouts

22,091

:ok_hand: Drag and drop so simple it hurts

🖱 A resizable and draggable component for React.

Quick Overview

React Beautiful DnD is a powerful and flexible drag and drop library for React applications. It provides a natural and intuitive drag and drop experience with smooth animations, while maintaining high performance and accessibility.

Pros

  • Highly customizable and flexible
  • Excellent performance, even with large lists
  • Strong focus on accessibility
  • Comprehensive documentation and examples

Cons

  • Limited to vertical lists and horizontal lists (no free-form dragging)
  • Learning curve can be steep for complex implementations
  • No built-in touch support for mobile devices
  • Relatively large bundle size

Code Examples

Basic list with drag and drop:

import React from 'react';
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';

const MyList = ({ items, onDragEnd }) => (
  <DragDropContext onDragEnd={onDragEnd}>
    <Droppable droppableId="list">
      {(provided) => (
        <ul {...provided.droppableProps} ref={provided.innerRef}>
          {items.map((item, index) => (
            <Draggable key={item.id} draggableId={item.id} index={index}>
              {(provided) => (
                <li
                  ref={provided.innerRef}
                  {...provided.draggableProps}
                  {...provided.dragHandleProps}
                >
                  {item.content}
                </li>
              )}
            </Draggable>
          ))}
          {provided.placeholder}
        </ul>
      )}
    </Droppable>
  </DragDropContext>
);

Multiple drag and drop lists:

import React from 'react';
import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';

const MultipleList = ({ lists, onDragEnd }) => (
  <DragDropContext onDragEnd={onDragEnd}>
    {Object.entries(lists).map(([listId, list]) => (
      <Droppable key={listId} droppableId={listId}>
        {(provided) => (
          <div {...provided.droppableProps} ref={provided.innerRef}>
            {list.map((item, index) => (
              <Draggable key={item.id} draggableId={item.id} index={index}>
                {(provided) => (
                  <div
                    ref={provided.innerRef}
                    {...provided.draggableProps}
                    {...provided.dragHandleProps}
                  >
                    {item.content}
                  </div>
                )}
              </Draggable>
            ))}
            {provided.placeholder}
          </div>
        )}
      </Droppable>
    ))}
  </DragDropContext>
);

Getting Started

  1. Install the package:

    npm install react-beautiful-dnd
    
  2. Import the necessary components:

    import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';
    
  3. Wrap your app or component with DragDropContext:

    <DragDropContext onDragEnd={this.onDragEnd}>
      {/* Your app content */}
    </DragDropContext>
    
  4. Use Droppable for drop targets and Draggable for draggable items:

    <Droppable droppableId="list">
      {(provided) => (
        <ul {...provided.droppableProps} ref={provided.innerRef}>
          <Draggable draggableId="item1" index={0}>
            {(provided) => (
              <li
                ref={provided.innerRef}
                {...provided.draggableProps}
                {...provided.dragHandleProps}
              >
                Item 1
              </li>
            )}
          </Draggable>
          {provided.placeholder}
        </ul>
    

Competitor Comparisons

20,973

Drag and Drop for React

Pros of react-dnd

  • More flexible and customizable, allowing for complex drag and drop scenarios
  • Supports touch events and works well on mobile devices
  • Provides a lower-level API, giving developers more control over the implementation

Cons of react-dnd

  • Steeper learning curve due to its flexibility and lower-level API
  • Requires more setup and configuration to get started
  • Less out-of-the-box styling and animations compared to react-beautiful-dnd

Code Comparison

react-dnd:

import { useDrag, useDrop } from 'react-dnd';

const [{ isDragging }, drag] = useDrag(() => ({
  type: 'ITEM',
  item: { id: props.id },
  collect: (monitor) => ({
    isDragging: !!monitor.isDragging(),
  }),
}));

react-beautiful-dnd:

import { Draggable } from 'react-beautiful-dnd';

<Draggable draggableId={props.id} index={props.index}>
  {(provided, snapshot) => (
    <div
      ref={provided.innerRef}
      {...provided.draggableProps}
      {...provided.dragHandleProps}
    >
      {props.children}
    </div>
  )}
</Draggable>

The code comparison shows that react-dnd requires more setup and uses hooks for implementation, while react-beautiful-dnd provides a more declarative approach with less boilerplate code.

A set of higher-order components to turn any list into an animated, accessible and touch-friendly sortable list✌️

Pros of react-sortable-hoc

  • More flexible and customizable, allowing for complex sorting scenarios
  • Supports both vertical and horizontal sorting out of the box
  • Lighter weight and potentially better performance for simpler use cases

Cons of react-sortable-hoc

  • Less polished animations and visual feedback during drag operations
  • Requires more setup and configuration for advanced features
  • Documentation is not as comprehensive or well-maintained

Code Comparison

react-sortable-hoc:

import { SortableContainer, SortableElement } from 'react-sortable-hoc';

const SortableItem = SortableElement(({value}) => <li>{value}</li>);

const SortableList = SortableContainer(({items}) => {
  return (
    <ul>
      {items.map((value, index) => (
        <SortableItem key={`item-${index}`} index={index} value={value} />
      ))}
    </ul>
  );
});

react-beautiful-dnd:

import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';

const List = ({items}) => (
  <DragDropContext onDragEnd={onDragEnd}>
    <Droppable droppableId="list">
      {(provided) => (
        <ul {...provided.droppableProps} ref={provided.innerRef}>
          {items.map((item, index) => (
            <Draggable key={item.id} draggableId={item.id} index={index}>
              {(provided) => (
                <li ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>
                  {item.content}
                </li>
              )}
            </Draggable>
          ))}
          {provided.placeholder}
        </ul>
      )}
    </Droppable>
  </DragDropContext>
);
29,843

Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.

Pros of Sortable

  • Framework-agnostic, works with vanilla JavaScript and various frameworks
  • Supports more features out-of-the-box, like multi-drag and swap animations
  • Smaller bundle size, potentially better performance for simpler use cases

Cons of Sortable

  • Less React-specific optimizations and integrations
  • Documentation and examples are not as comprehensive for React use cases
  • May require more manual setup for advanced React-specific functionality

Code Comparison

react-beautiful-dnd:

import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';

<DragDropContext onDragEnd={onDragEnd}>
  <Droppable droppableId="list">
    {(provided) => (
      <ul {...provided.droppableProps} ref={provided.innerRef}>
        {items.map((item, index) => (
          <Draggable key={item.id} draggableId={item.id} index={index}>
            {(provided) => (
              <li ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>
                {item.content}
              </li>
            )}
          </Draggable>
        ))}
        {provided.placeholder}
      </ul>
    )}
  </Droppable>
</DragDropContext>

Sortable:

import Sortable from 'sortablejs';

const el = document.getElementById('items');
const sortable = Sortable.create(el, {
  animation: 150,
  ghostClass: 'blue-background-class',
  onEnd: (evt) => {
    // Handle drag end
  }
});
10,837

Infinite responsive, sortable, filterable and draggable layouts

Pros of Muuri

  • Framework-agnostic: Works with any JavaScript framework or vanilla JS
  • Supports both grid and list layouts with advanced sorting and filtering
  • Highly customizable with extensive API and event system

Cons of Muuri

  • Steeper learning curve due to more complex API
  • Less React-specific optimizations and integrations
  • Requires more manual setup for accessibility features

Code Comparison

Muuri:

const grid = new Muuri('.grid', {
  dragEnabled: true,
  dragSort: true
});

grid.on('dragEnd', (item) => {
  console.log('Item moved:', item);
});

react-beautiful-dnd:

<DragDropContext onDragEnd={onDragEnd}>
  <Droppable droppableId="list">
    {(provided) => (
      <div {...provided.droppableProps} ref={provided.innerRef}>
        {items.map((item, index) => (
          <Draggable key={item.id} draggableId={item.id} index={index}>
            {(provided) => (
              <div ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>
                {item.content}
              </div>
            )}
          </Draggable>
        ))}
        {provided.placeholder}
      </div>
    )}
  </Droppable>
</DragDropContext>
22,091

:ok_hand: Drag and drop so simple it hurts

Pros of Dragula

  • Lightweight and framework-agnostic, making it versatile for various projects
  • Simple API and easy setup, requiring minimal configuration
  • Supports touch events out of the box for mobile compatibility

Cons of Dragula

  • Less feature-rich compared to React Beautiful DnD, lacking advanced functionalities
  • Not specifically optimized for React, which may result in less seamless integration
  • Limited built-in animations and visual feedback options

Code Comparison

React Beautiful DnD:

import { DragDropContext, Droppable, Draggable } from 'react-beautiful-dnd';

<DragDropContext onDragEnd={onDragEnd}>
  <Droppable droppableId="list">
    {(provided) => (
      <ul {...provided.droppableProps} ref={provided.innerRef}>
        {items.map((item, index) => (
          <Draggable key={item.id} draggableId={item.id} index={index}>
            {(provided) => (
              <li ref={provided.innerRef} {...provided.draggableProps} {...provided.dragHandleProps}>
                {item.content}
              </li>
            )}
          </Draggable>
        ))}
        {provided.placeholder}
      </ul>
    )}
  </Droppable>
</DragDropContext>

Dragula:

import dragula from 'dragula';

dragula([document.querySelector('#left'), document.querySelector('#right')])
  .on('drag', function(el) {
    el.className += ' is-moving';
  })
  .on('drop', function(el) {
    el.className = el.className.replace('is-moving', '');
  });

🖱 A resizable and draggable component for React.

Pros of react-rnd

  • Supports both resizing and dragging of elements
  • Allows for more flexible positioning and sizing of components
  • Provides fine-grained control over resize and drag behavior

Cons of react-rnd

  • Less optimized for complex list reordering scenarios
  • May require more manual setup for accessibility features
  • Doesn't provide built-in animations for drag and drop operations

Code Comparison

react-rnd:

<Rnd
  default={{
    x: 0,
    y: 0,
    width: 320,
    height: 200,
  }}
>
  Resizable and draggable component
</Rnd>

react-beautiful-dnd:

<DragDropContext onDragEnd={onDragEnd}>
  <Droppable droppableId="list">
    {(provided) => (
      <div {...provided.droppableProps} ref={provided.innerRef}>
        {items.map((item, index) => (
          <Draggable key={item.id} draggableId={item.id} index={index}>
            {(provided) => (
              <div
                ref={provided.innerRef}
                {...provided.draggableProps}
                {...provided.dragHandleProps}
              >
                {item.content}
              </div>
            )}
          </Draggable>
        ))}
        {provided.placeholder}
      </div>
    )}
  </Droppable>
</DragDropContext>

react-beautiful-dnd is more focused on list reordering and provides a more structured API for handling drag and drop within lists. react-rnd offers a simpler API for individual element manipulation but requires more setup for complex scenarios.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

⚠️ Deprecated

Hey all,

We are taking the next step in saying thank you and goodbye to our friend react-beautiful-dnd.

  • 🔔 We will be soon deprecating react-beautiful-dnd on npm. When we do you will start to get console warnings in your build tools.
  • 🔒 On Apr 30, 2025 (six months from posting) we will archiving the react-beautiful-dnd Github repository (it will become read only).

Thank you everybody for your support of this project.

More information



react beautiful dnd logo

react-beautiful-dnd (rbd)

Beautiful and accessible drag and drop for lists with React

CircleCI branch npm

quote application example

Play with this example if you want!

Core characteristics

  • Beautiful and natural movement of items 💐
  • Accessible: powerful keyboard and screen reader support ♿️
  • Extremely performant 🚀
  • Clean and powerful api which is simple to get started with
  • Plays extremely well with standard browser interactions
  • Unopinionated styling
  • No creation of additional wrapper dom nodes - flexbox and focus management friendly!

Get started 👩‍🏫

We have created a free course on egghead.io 🥚 to help you get started with react-beautiful-dnd as quickly as possible.

course-logo

Currently supported feature set ✅

  • Vertical lists ↕
  • Horizontal lists ↔
  • Movement between lists (▤ ↔ ▤)
  • Virtual list support 👾 - unlocking 10,000 items @ 60fps
  • Combining items
  • Mouse 🐭, keyboard 🎹♿️ and touch 👉📱 (mobile, tablet and so on) support
  • Multi drag support
  • Incredible screen reader support ♿️ - we provide an amazing experience for english screen readers out of the box 📦. We also provide complete customisation control and internationalisation support for those who need it 💖
  • Conditional dragging and conditional dropping
  • Multiple independent lists on the one page
  • Flexible item sizes - the draggable items can have different heights (vertical lists) or widths (horizontal lists)
  • Add and remove items during a drag
  • Compatible with semantic <table> reordering - table pattern
  • Auto scrolling - automatically scroll containers and the window as required during a drag (even with keyboard 🔥)
  • Custom drag handles - you can drag a whole item by just a part of it
  • Able to move the dragging item to another element while dragging (clone, portal) - Reparenting your <Draggable />
  • Create scripted drag and drop experiences 🎮
  • Allows extensions to support for any input type you like 🕹
  • 🌲 Tree support through the @atlaskit/tree package
  • A <Droppable /> list can be a scroll container (without a scrollable parent) or be the child of a scroll container (that also does not have a scrollable parent)
  • Independent nested lists - a list can be a child of another list, but you cannot drag items from the parent list into a child list
  • Server side rendering (SSR) compatible - see resetServerContext()
  • Plays well with nested interactive elements by default

Motivation 🤔

react-beautiful-dnd exists to create beautiful drag and drop for lists that anyone can use - even people who cannot see. For a good overview of the history and motivations of the project you can take a look at these external resources:

Not for everyone ✌️

There are a lot of libraries out there that allow for drag and drop interactions within React. Most notable of these is the amazing react-dnd. It does an incredible job at providing a great set of drag and drop primitives which work especially well with the wildly inconsistent html5 drag and drop feature. react-beautiful-dnd is a higher level abstraction specifically built for lists (vertical, horizontal, movement between lists, nested lists and so on). Within that subset of functionality react-beautiful-dnd offers a powerful, natural and beautiful drag and drop experience. However, it does not provide the breadth of functionality offered by react-dnd. So react-beautiful-dnd might not be for you depending on what your use case is.

Documentation 📖

About 👋

Sensors 🔉

The ways in which somebody can start and control a drag

API 🏋️‍

diagram

Guides 🗺

Patterns 👷‍

Support 👩‍⚕️

Read this in other languages 🌎

Creator ✍️

Alex Reardon @alexandereardon

Alex is no longer personally maintaning this project. The other wonderful maintainers are carrying this project forward.

Maintainers

Collaborators 🤝

NPM DownloadsLast 30 Days