Skip to content

Commit 51b0dea

Browse files
committed
feat: add isUnorderedDragTarget
1 parent 72e714b commit 51b0dea

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@headless-tree/core": patch
3+
---
4+
5+
Added `isUnorderedDragTarget` as alternative to `isDragTarget` for easier detection of drag type

packages/core/src/features/drag-and-drop/feature.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,13 @@ export const dragAndDropFeature: FeatureImplementation = {
332332
return target ? target.item.getId() === item.getId() : false;
333333
},
334334

335+
isUnorderedDragTarget: ({ tree, item }) => {
336+
const target = tree.getDragTarget();
337+
return target
338+
? !isOrderedDragTarget(target) && target.item.getId() === item.getId()
339+
: false;
340+
},
341+
335342
isDragTargetAbove: ({ tree, item }) => {
336343
const target = tree.getDragTarget();
337344

packages/core/src/features/drag-and-drop/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ export type DragAndDropFeatureDef<T> = {
108108
) => Record<string, any>;
109109
};
110110
itemInstance: {
111+
/** Checks if the user is dragging in a way which makes this the new parent of the dragged items, either by dragging on top of
112+
* this item, or by dragging inbetween children of this item. See @{isUnorderedDragTarget} if the latter is undesirable. */
111113
isDragTarget: () => boolean;
114+
115+
/** As opposed to @{isDragTarget}, this will not be true if the target is inbetween children of this item. This returns only true
116+
* if the user is dragging directly on top of this item. */
117+
isUnorderedDragTarget: () => boolean;
112118
isDragTargetAbove: () => boolean;
113119
isDragTargetBelow: () => boolean;
114120
isDraggingOver: () => boolean;

0 commit comments

Comments
 (0)