diff --git a/apps/docs/react/guides/multiple-sortable-lists.mdx b/apps/docs/react/guides/multiple-sortable-lists.mdx
index f3bed326..6c286e54 100644
--- a/apps/docs/react/guides/multiple-sortable-lists.mdx
+++ b/apps/docs/react/guides/multiple-sortable-lists.mdx
@@ -6,6 +6,7 @@ mode: "wide"
---
import {Story} from '/snippets/story.mdx';
+import {CodeSandbox} from '/snippets/code.mdx';
@@ -21,150 +22,38 @@ We'll be setting up three columns, and each column will have its own list of ite
First, let's set up the initial setup for the columns and items. We'll be creating three files, `App.js`, `Column.js`, and `Item.js`, and applying some basic styles in the `Styles.css` file.
-
-```jsx App.js
-import {Column} from './Column';
-import {Item} from './Item';
-import "./Styles.css";
-
-export function App() {
- const [items] = useState({
- A: ['A0', 'A1', 'A2'],
- B: ['B0', 'B1'],
- C: [],
- });
-
- return (
-
- );
-}
-```
-```jsx Column.js
-import React from 'react';
-
-export function Column({children, id}) {
- return (
-
- {children}
-
- );
-}
-```
-
-```jsx Item.js
-import React from 'react';
-
-export function Item({id, index}) {
- return (
-
- );
-}
-
-const styles = {
- appearance: "none", backgroundColor: "#FFF", color: "#666";
- padding: "12px 20px"; borderRadius: "5px"
-};
-```
-
-```css Styles.css
-.Root {
- display: inline-flex;
- flex-direction: row;
- gap: 20;
-}
-
-.Column {
- display: flex;
- flex-direction: column;
- gap: 10px;
- padding: 20px;
- min-width: 200px;
- background-color: rgba(0, 0, 0, 0.1);
- border-radius: 10px;
-}
-
-.Item {
- appearance: none;
- background: #FFF;
- color: #666;
- padding: 12px 20px;
- border: none;
- border-radius: 5px;
- cursor: grab;
-};
-```
-
-
-
+
## Adding drag and drop functionality
Now, let's add drag and drop functionality to the items. We'll be using the [useSortable](/react/hooks/use-sortable) hook to make the items sortable. Let's modify the `Item` component to make it sortable:
-```jsx Item.js
-import React from 'react';
-import {useSortable} from '@dnd-kit/react/sortable';
-export function Item({id, index, column}) {
- const {ref} = useSortable({
- id,
- index,
- type: 'item',
- accept: 'item',
- group: column
- });
-
- return (
-
- );
-}
-```
-
-
+
As you can see, we've added the `useSortable` hook to the `Item` component. We've also passed the `id`, `index`, `type`, `accept`, and `group` props to the hook.
-This creates an uncontrolled list of sortable items that can be sorted within each column. In order to be able to move items between columns, we need to add some additional logic.
+This creates an uncontrolled list of sortable items that can be sorted within each column, and across columns thanks to the `group` property. However, in order to be able to move items to an empty column, we need to add some additional logic.
## Moving items between columns
-To move items between columns, we need to add a drop target to each column.
+To move items to empty columns, we need to add make each column droppable.
We'll be using the [useDroppable](/react/hooks/use-droppable) hook to create a drop target for each column. Let's modify the `Column` component to make it droppable:
-```jsx Column.js
-import React from 'react';
-import {useDroppable} from '@dnd-kit/react';
-import {CollisionPriority} from '@dnd-kit/abstract';
-
-export function Column({children, id}) {
- const {ref} = useDroppable({
- id,
- type: 'column',
- accept: 'item',
- collisionPriority: CollisionPriority.Low,
- });
-
- return (
-
- {children}
-
- );
-}
-```
+We're setting the `collisionPriority` to `CollisionPriority.Low` to prioritize collisions of items over collisions of columns. Learn more about [detecting collisions](/concepts/droppable#detecting-collisions).
@@ -172,81 +61,32 @@ This will allow us to drop items into each column. However, we still need to han
We'll be using the [DragDropProvider](/react/components/drag-drop-provider) component to listen and respond to the drag and drop events. Let's modify the `App` component to add the `DragDropProvider`. We'll be using the `move` helper function from `@dnd-kit/helpers` to help us mutate the array of items between columns:
-```jsx App.js
-import React, {useState} from 'react';
-import {DragDropProvider} from '@dnd-kit/react';
-import {move} from '@dnd-kit/helpers';
-import "./Styles.css";
-
-import {Column} from './Column';
-import {Item} from './Item';
-
-export function App() {
- const [items, setItems] = useState({
- A: ['A0', 'A1', 'A2'],
- B: ['B0', 'B1'],
- C: [],
- });
-
- return (
- {
- setItems((items) => move(items, eventt));
- }}
- >
-
-
- );
-}
-```
+
As you can see, we've added the `DragDropProvider` component to the `App` component. We've also added an `onDragOver` event handler to listen for drag and drop events.
When an item is dragged over a column, the `onDragOver` event handler will be called. We'll use the `move` helper function to move the item between columns.
-The result is a sortable list of items that can be moved between columns:
-
-
+The result is a sortable list of items that can be moved between columns.
### Making the columns sortable
If you want to make the columns themselves sortable, you can use the `useSortable` hook in the `Column` component.
Here's how you can modify the `Column` component to make it sortable:
-```jsx Column.js
-import React from 'react';
-import {CollisionPriority} from '@dnd-kit/abstract';
-import {useSortable} from '@dnd-kit/react/sortable';
-export function Column({children, id, index}) {
- const {ref} = useSortable({
- id,
- index,
- type: 'column',
- collisionPriority: CollisionPriority.Low,
- accept: ['item', 'column'],
- });
-
- return (
-
- {children}
-
- );
-}
-```
+You'll also need to pass the column `index` prop to the `Column` component in the `App` component.
-
-
If we want to control the state of the columns in React, we can update the `App` component to handle the column order in the `onDragEnd` callback:
```jsx App.js
@@ -361,3 +201,226 @@ export function App({style = styles}) {
```
Optimistic updates performed by `@dnd-kit` are automatically reverted when a drag operation is canceled.
+
+export const App = `import React, {useState} from 'react';
+import {Column} from './Column';
+import {Item} from './Item';
+import './Styles.css';
+
+export default function App() {
+ const [items] = useState({
+ A: ['A0', 'A1', 'A2'],
+ B: ['B0', 'B1'],
+ C: [],
+ });
+
+ return (
+