Skip to content

Commit bb0b653

Browse files
committed
fix(DragDropSort): enable mobile drag-and-drop support
Set touch-action: none on the drag activator element (DragButton when useDragButton is true, wrapper div otherwise) to prevent the browser from intercepting touch events for native scrolling. Without this, mobile browsers fire pointercancel before the PointerSensor can activate the drag. Also adds activationConstraint: { distance: 8 } to PointerSensor so the drag only activates after deliberate pointer movement, preventing accidental drags on both desktop and mobile. Fixes #12415
1 parent 6b93dbd commit bb0b653

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

packages/react-drag-drop/src/components/DragDrop/DragDropContainer.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ export const DragDropContainer: React.FunctionComponent<DragDropContainerProps>
103103
);
104104

105105
const sensors = useSensors(
106-
useSensor(PointerSensor),
106+
useSensor(PointerSensor, {
107+
activationConstraint: { distance: 8 }
108+
}),
107109
useSensor(KeyboardSensor, {
108110
coordinateGetter: sortableKeyboardCoordinates
109111
})

packages/react-drag-drop/src/components/DragDrop/Draggable.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
2828

2929
const style = {
3030
transform: CSS.Transform.toString(transform),
31-
transition
31+
transition,
32+
...(!useDragButton && { touchAction: 'none' as const })
3233
};
3334

3435
return useDragButton ? (
@@ -38,7 +39,7 @@ export const Draggable: React.FunctionComponent<DraggableProps> = ({
3839
style={style}
3940
{...props}
4041
>
41-
<DragButton {...attributes} {...listeners} />
42+
<DragButton {...attributes} {...listeners} style={{ touchAction: 'none' }} />
4243
{children}
4344
</div>
4445
) : (

0 commit comments

Comments
 (0)