Skip to content

Commit 8daaca3

Browse files
committed
fix: always map to bottom offset when dropping below tree
1 parent aed269e commit 8daaca3

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

packages/core/src/drag/useDraggingPosition.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ export const useDraggingPosition = () => {
9696
? 0.2
9797
: 0.5;
9898

99-
if (hoveringPosition % 1 < lineThreshold) {
99+
if (hoveringPosition - 0.5 >= treeLinearItems.length - 1) {
100+
// very bottom, always use offset "bottom"
101+
offset = 'bottom';
102+
} else if (hoveringPosition % 1 < lineThreshold) {
100103
offset = 'top';
101104
} else if (hoveringPosition % 1 > 1 - lineThreshold) {
102105
offset = 'bottom';

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,21 @@ describe('dnd basics', () => {
373373
});
374374

375375
describe('special drop positions', () => {
376+
it.each([0, 5, 10, 15, 20, 30, 40])(
377+
'drops at very bottom +%ipx',
378+
async offset => {
379+
const test = await new TestUtil().renderOpenTree();
380+
await test.startDrag('target');
381+
await test.dragOver('cannot-rename', 'bottom', 20, offset);
382+
await test.drop();
383+
await test.expectVisibleItemContents('special', [
384+
'cannot-move',
385+
'cannot-rename',
386+
'target',
387+
]);
388+
}
389+
);
390+
376391
it('doesnt allow dropping into itself', async () => {
377392
const test = await new TestUtil().renderOpenTree();
378393
await test.startDrag('a');

packages/core/test/helpers/TestUtil.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ export class TestUtil {
149149
public async dragOver(
150150
title: string,
151151
position?: 'top' | 'bottom',
152-
indent?: number
152+
indent?: number,
153+
additionalYCoord = 0
153154
) {
154155
await act(async () => {
155156
const items = await this.renderProps!.findAllByTestId('title');
@@ -161,7 +162,8 @@ export class TestUtil {
161162
clientX: indent !== undefined ? indent * 10 : 9999,
162163
clientY:
163164
itemIndex * 10 +
164-
(position === 'top' ? 1 : position === 'bottom' ? 9 : 5),
165+
(position === 'top' ? 1 : position === 'bottom' ? 9 : 5) +
166+
additionalYCoord,
165167
} as any,
166168
'tree-1',
167169
{ current: this.containerRef ?? undefined }

0 commit comments

Comments
 (0)