Skip to content

Commit 7ee3a7e

Browse files
committed
fix: insertion order when dropping at folder (#315)
1 parent a825a76 commit 7ee3a7e

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/core/src/uncontrolledEnvironment/UncontrolledTreeEnvironment.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ export const UncontrolledTreeEnvironment = React.forwardRef<
131131
}}
132132
onDrop={async (items, target) => {
133133
const promises: Promise<void>[] = [];
134-
for (const item of items) {
134+
135+
// when dropped between items, items are injected at top of insertion point each
136+
const orderedItems =
137+
target.targetType === 'between-items' ? [...items].reverse() : items;
138+
139+
for (const item of orderedItems) {
135140
const parent = Object.values(currentItems).find(potentialParent =>
136141
potentialParent.children?.includes(item.index)
137142
);

packages/core/test/dnd-basics.spec.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,23 @@ describe('dnd basics', () => {
202202
]);
203203
});
204204

205+
it('drag items with scrambled order into another folder', async () => {
206+
const test = await new TestUtil().renderOpenTree();
207+
await test.selectItems('aac', 'aad', 'aab');
208+
await test.startDrag('aab');
209+
await test.dragOver('target-parent');
210+
await test.drop();
211+
await test.expectVisibleItemContents('aa', ['aaa']);
212+
await test.expectVisibleItemContents('target-parent', [
213+
'before',
214+
'target',
215+
'after',
216+
'aab',
217+
'aac',
218+
'aad',
219+
]);
220+
});
221+
205222
it('drag folders into another opened folder', async () => {
206223
const test = await new TestUtil().renderOpenTree();
207224
await test.selectItems('ab', 'ac', 'ad');

0 commit comments

Comments
 (0)