Skip to content

Commit 418bb92

Browse files
authored
fix: improve mobile touch support for dnd (#15771)
replaces` PointerSensor` with `MouseSensor` + `TouchSensor` (200ms press-and-hold delay) in both modular dashboard widget drag and `DraggableSortable` component, so touch gestures no longer conflict with scrolling on mobile devices
1 parent 7a3f43f commit 418bb92

2 files changed

Lines changed: 24 additions & 4 deletions

File tree

  • packages
    • next/src/views/Dashboard/Default/ModularDashboard/utils
    • ui/src/elements/DraggableSortable

packages/next/src/views/Dashboard/Default/ModularDashboard/utils/sensors.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import type { KeyboardCoordinateGetter, KeyboardSensorOptions } from '@dnd-kit/core'
22

3-
import { KeyboardCode, KeyboardSensor, PointerSensor, useSensor, useSensors } from '@dnd-kit/core'
3+
import {
4+
KeyboardCode,
5+
KeyboardSensor,
6+
MouseSensor,
7+
TouchSensor,
8+
useSensor,
9+
useSensors,
10+
} from '@dnd-kit/core'
411

512
type DroppablePosition = {
613
centerX: number
@@ -307,11 +314,17 @@ class DirectFocusKeyboardSensor extends KeyboardSensor {
307314

308315
export function useDashboardSensors() {
309316
return useSensors(
310-
useSensor(PointerSensor, {
317+
useSensor(MouseSensor, {
311318
activationConstraint: {
312319
distance: 5,
313320
},
314321
}),
322+
useSensor(TouchSensor, {
323+
activationConstraint: {
324+
delay: 200,
325+
tolerance: 5,
326+
},
327+
}),
315328
useSensor(DirectFocusKeyboardSensor, {
316329
coordinateGetter: droppableJumpKeyboardCoordinateGetter,
317330
}),

packages/ui/src/elements/DraggableSortable/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import {
55
closestCenter,
66
DndContext,
77
KeyboardSensor,
8-
PointerSensor,
8+
MouseSensor,
9+
TouchSensor,
910
useDroppable,
1011
useSensor,
1112
useSensors,
@@ -28,11 +29,17 @@ export const DraggableSortable: React.FC<Props> = (props) => {
2829
})
2930

3031
const sensors = useSensors(
31-
useSensor(PointerSensor, {
32+
useSensor(MouseSensor, {
3233
activationConstraint: {
3334
distance: 5,
3435
},
3536
}),
37+
useSensor(TouchSensor, {
38+
activationConstraint: {
39+
delay: 200,
40+
tolerance: 5,
41+
},
42+
}),
3643
useSensor(KeyboardSensor, {
3744
coordinateGetter: sortableKeyboardCoordinates,
3845
}),

0 commit comments

Comments
 (0)