fix: fixed scrolling by draggable on mobile
This commit is contained in:
@ -1,33 +1,28 @@
|
||||
import {
|
||||
KeyboardSensor,
|
||||
PointerSensor,
|
||||
MouseSensor,
|
||||
TouchSensor,
|
||||
useSensor,
|
||||
useSensors,
|
||||
} from "@dnd-kit/core";
|
||||
import { sortableKeyboardCoordinates } from "@dnd-kit/sortable";
|
||||
import useIsMobile from "@/hooks/useIsMobile";
|
||||
|
||||
const useDndSensors = () => {
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
const sensorOptions = {
|
||||
activationConstraint: isMobile
|
||||
? {
|
||||
delay: 500,
|
||||
tolerance: 5,
|
||||
}
|
||||
: {
|
||||
distance: 5,
|
||||
},
|
||||
};
|
||||
|
||||
return useSensors(
|
||||
useSensor(PointerSensor, sensorOptions),
|
||||
useSensor(MouseSensor, {
|
||||
activationConstraint: {
|
||||
distance: 8,
|
||||
},
|
||||
}),
|
||||
useSensor(KeyboardSensor, {
|
||||
coordinateGetter: sortableKeyboardCoordinates,
|
||||
}),
|
||||
useSensor(TouchSensor, sensorOptions)
|
||||
useSensor(TouchSensor, {
|
||||
activationConstraint: {
|
||||
delay: 300,
|
||||
tolerance: 5,
|
||||
},
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@ -18,12 +18,9 @@ const DragHandle = ({ id, children, style, disabled }: Props) => {
|
||||
<div
|
||||
{...attributes}
|
||||
{...listeners}
|
||||
onTouchStart={e => !disabled && e.stopPropagation()}
|
||||
onTouchMove={e => !disabled && e.stopPropagation()}
|
||||
style={{
|
||||
width: "100wv",
|
||||
cursor: disabled ? "default" : "grab",
|
||||
touchAction: disabled ? "auto" : "none",
|
||||
...style,
|
||||
}}
|
||||
ref={setNodeRef}>
|
||||
|
||||
Reference in New Issue
Block a user