Skip to content

Commit 6dd6bd8

Browse files
authored
Fixing directory drop for docs low level DnD api example (#3582)
* Fixing directory drops for low level API drop example * small revision
1 parent c22d969 commit 6dd6bd8

File tree

1 file changed

+10
-8
lines changed
  • packages/@react-spectrum/dnd/docs

1 file changed

+10
-8
lines changed

packages/@react-spectrum/dnd/docs/dnd.mdx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ let onInsert = async (e) => {
240240
} = e;
241241

242242
let processedItems = await Promise.all(
243-
items.map(async item => JSON.parse(await item.getText(acceptedDragTypes[0])))
243+
items.map(async item => JSON.parse(await item.getText('adobe-app')))
244244
);
245245

246246
if (target.dropPosition === 'before') {
@@ -262,7 +262,7 @@ let onItemDrop = async (e) => {
262262
target
263263
} = e;
264264
let processedItems = await Promise.all(
265-
items.map(async item => JSON.parse(await item.getText(acceptedDragTypes[0])))
265+
items.map(async item => JSON.parse(await item.getText('adobe-app')))
266266
);
267267
let targetItem = list.getItem(target.key);
268268
list.update(target.key, {...targetItem, childNodes: [...targetItem.childNodes, ...processedItems]});
@@ -291,15 +291,17 @@ function DroppableList() {
291291
{id: 'k', type: 'folder', name: 'Apps', childNodes: []}
292292
]
293293
});
294-
let acceptedDragTypes = ['adobe-app'];
294+
295295
let {dragAndDropHooks} = useDragAndDrop({
296+
acceptedDragTypes: ['adobe-app'],
297+
shouldAcceptItemDrop: (target) => !!list.getItem(target.key).childNodes,
296298
onInsert: async (e) => {
297299
let {
298300
items,
299301
target
300302
} = e;
301303
let processedItems = await Promise.all(
302-
items.map(async item => JSON.parse(await item.getText(acceptedDragTypes[0])))
304+
items.map(async item => JSON.parse(await item.getText('adobe-app')))
303305
);
304306

305307
if (target.dropPosition === 'before') {
@@ -314,13 +316,11 @@ function DroppableList() {
314316
target
315317
} = e;
316318
let processedItems = await Promise.all(
317-
items.map(async item => JSON.parse(await item.getText(acceptedDragTypes[0])))
319+
items.map(async item => JSON.parse(await item.getText('adobe-app')))
318320
);
319321
let targetItem = list.getItem(target.key);
320322
list.update(target.key, {...targetItem, childNodes: [...targetItem.childNodes, ...processedItems]});
321-
},
322-
acceptedDragTypes,
323-
shouldAcceptItemDrop: (target) => !!list.getItem(target.key).childNodes
323+
}
324324
});
325325

326326
return (
@@ -355,6 +355,8 @@ see the [API section](#low-level-drop-handlers-and-options) below and the `useDr
355355
The ListView below allows external directories to be dropped at its root level or between existing items. Files of a specific type can be dropped on certain pre-existing directories only.
356356

357357
```tsx example
358+
import {DIRECTORY_DRAG_TYPE} from '@react-spectrum/dnd';
359+
358360
function DroppableListLowLevelAPI() {
359361
let list = useListData({
360362
initialItems: [

0 commit comments

Comments
 (0)