Skip to content

Commit ac58b05

Browse files
committed
fix DragBetweenListsExample to use RAC
1 parent 4e436bb commit ac58b05

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

packages/dev/s2-docs/pages/react-aria/blog/DragBetweenListsExample.tsx

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
'use client';
22

3-
import {ListView, Item, Text, useListData, useDragAndDrop} from '@adobe/react-spectrum';
4-
import {style} from '@react-spectrum/s2/style';
5-
import File from '@spectrum-icons/illustrations/File';
6-
import Folder from '@spectrum-icons/illustrations/Folder';
3+
import {GridList, GridListItem} from 'vanilla-starter/GridList';
4+
import {useDragAndDrop, isTextDropItem} from 'react-aria-components';
5+
import {useListData} from 'react-stately';
6+
import File from '@react-spectrum/s2/icons/File';
7+
import Folder from '@react-spectrum/s2/icons/Folder';
78
import React from 'react';
89

9-
function BidirectionalDnDListView(props) {
10+
function BidirectionalDnDGridList(props) {
1011
let {list} = props;
1112
let {dragAndDropHooks} = useDragAndDrop({
1213
acceptedDragTypes: ['custom-app-type-bidirectional'],
@@ -28,15 +29,17 @@ function BidirectionalDnDListView(props) {
2829
target
2930
} = e;
3031
let processedItems = await Promise.all(
31-
items.map(async item => JSON.parse(await item.getText('custom-app-type-bidirectional')))
32+
items
33+
.filter(isTextDropItem)
34+
.map(async item => JSON.parse(await item.getText('custom-app-type-bidirectional')))
3235
);
3336
if (target.dropPosition === 'before') {
3437
list.insertBefore(target.key, ...processedItems);
3538
} else if (target.dropPosition === 'after') {
3639
list.insertAfter(target.key, ...processedItems);
3740
}
3841
},
39-
onReorder: async (e) => {
42+
onReorder: (e) => {
4043
let {
4144
keys,
4245
target
@@ -53,7 +56,9 @@ function BidirectionalDnDListView(props) {
5356
items
5457
} = e;
5558
let processedItems = await Promise.all(
56-
items.map(async item => JSON.parse(await item.getText('custom-app-type-bidirectional')))
59+
items
60+
.filter(isTextDropItem)
61+
.map(async item => JSON.parse(await item.getText('custom-app-type-bidirectional')))
5762
);
5863
list.append(...processedItems);
5964
},
@@ -73,20 +78,20 @@ function BidirectionalDnDListView(props) {
7378
});
7479

7580
return (
76-
<ListView
81+
<GridList
7782
aria-label={props['aria-label']}
7883
selectionMode="multiple"
79-
width="size-3600"
80-
height="size-3600"
84+
layout="list"
8185
items={list.items}
82-
dragAndDropHooks={dragAndDropHooks}>
86+
dragAndDropHooks={dragAndDropHooks}
87+
style={{width: 300, height: 300}}>
8388
{item => (
84-
<Item textValue={item.name}>
89+
<GridListItem textValue={item.name}>
8590
{item.type === 'folder' ? <Folder /> : <File />}
86-
<Text>{item.name}</Text>
87-
</Item>
91+
<span>{item.name}</span>
92+
</GridListItem>
8893
)}
89-
</ListView>
94+
</GridList>
9095
);
9196
}
9297

@@ -115,9 +120,9 @@ export default function DragBetweenListsExample() {
115120

116121

117122
return (
118-
<div className={style({display: 'flex', flexWrap: 'wrap', gap: 8})}>
119-
<BidirectionalDnDListView list={list1} aria-label="First ListView in drag between list example" />
120-
<BidirectionalDnDListView list={list2} aria-label="Second ListView in drag between list example" />
123+
<div style={{display: 'flex', justifyContent: 'center', flexWrap: 'wrap', gap: 8}}>
124+
<BidirectionalDnDGridList list={list1} aria-label="First GridList in drag between list example" />
125+
<BidirectionalDnDGridList list={list2} aria-label="Second GridList in drag between list example" />
121126
</div>
122127
);
123128
}

packages/dev/s2-docs/pages/react-aria/blog/drag-and-drop.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import heroVideo from 'url:../../../../docs/pages/assets/dnd.mp4';
1515
import dndKeyboard from 'url:../../../../docs/pages/assets/dnd-keyboard.mp4';
1616
import dndMobile from 'url:../../../../docs/pages/assets/dnd-mobile.mp4';
1717
import dndMobileVTT from 'url:../../../../docs/pages/assets/dnd-mobile.vtt';
18+
import DragBetweenListsExample from './DragBetweenListsExample';
1819

1920
import {BlogPostLayout} from '../../../src/Layout';
2021
export default BlogPostLayout;
@@ -89,7 +90,7 @@ The [useDraggableCollection](../useDraggableCollection.html) and [useDroppableCo
8990

9091
Try out an example below, which allows reordering and dragging elements between lists.
9192

92-
TODO: DragBetweenListsExample
93+
<DragBetweenListsExample />
9394

9495
## Challenges
9596

0 commit comments

Comments
 (0)