fix(app): make sidebar reordering respond immediately
Mouse input inherited the touch hold delay. Split activation by input so mouse dragging begins after deliberate movement while touch retains long-press arbitration.
This commit is contained in:
@@ -4,7 +4,8 @@ import {
|
||||
DndContext,
|
||||
closestCenter,
|
||||
KeyboardSensor,
|
||||
PointerSensor,
|
||||
MouseSensor,
|
||||
TouchSensor,
|
||||
type Modifier,
|
||||
useSensor,
|
||||
useSensors,
|
||||
@@ -17,7 +18,7 @@ import {
|
||||
} from "@dnd-kit/sortable";
|
||||
import { CSS } from "@dnd-kit/utilities";
|
||||
import type { DraggableListProps, DraggableRenderItemInfo } from "./draggable-list.types";
|
||||
import { getPointerActivationConstraint, useDragReorderState } from "./drag-reorder";
|
||||
import { getDragActivationConstraints, useDragReorderState } from "./drag-reorder";
|
||||
|
||||
export type { DraggableListProps, DraggableRenderItemInfo };
|
||||
|
||||
@@ -27,10 +28,10 @@ const restrictToVerticalAxis: Modifier = ({ transform }) => ({
|
||||
});
|
||||
|
||||
const DND_MODIFIERS = [restrictToVerticalAxis];
|
||||
const POINTER_ACTIVATION_CONFIG = {
|
||||
defaultDistance: 6,
|
||||
holdDelayMs: 250,
|
||||
holdTolerance: 8,
|
||||
const DRAG_ACTIVATION_CONFIG = {
|
||||
movementDistance: 6,
|
||||
touchHoldDelayMs: 180,
|
||||
touchHoldTolerance: 8,
|
||||
};
|
||||
|
||||
interface SortableItemProps<T> {
|
||||
@@ -145,14 +146,14 @@ export function DraggableList<T>({
|
||||
onDragEnd,
|
||||
onDragBegin,
|
||||
});
|
||||
const pointerActivationConstraint = getPointerActivationConstraint(
|
||||
useDragHandle,
|
||||
POINTER_ACTIVATION_CONFIG,
|
||||
);
|
||||
const activationConstraints = getDragActivationConstraints(useDragHandle, DRAG_ACTIVATION_CONFIG);
|
||||
|
||||
const sensors = useSensors(
|
||||
useSensor(PointerSensor, {
|
||||
activationConstraint: pointerActivationConstraint,
|
||||
useSensor(MouseSensor, {
|
||||
activationConstraint: activationConstraints.mouse,
|
||||
}),
|
||||
useSensor(TouchSensor, {
|
||||
activationConstraint: activationConstraints.touch,
|
||||
}),
|
||||
useSensor(KeyboardSensor, {
|
||||
coordinateGetter: sortableKeyboardCoordinates,
|
||||
|
||||
Reference in New Issue
Block a user