Use touch-action: pan-y to fix DnD vs scroll (#2350)
* Fix handleTouchMove not handling leaving elements * Fix DnD vs scroll on mobile
This commit is contained in:
parent
0968c77bdf
commit
1dc4018a3c
@ -18,7 +18,7 @@
|
|||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.draggable {
|
.draggable {
|
||||||
/* https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action */
|
/* https://developer.mozilla.org/en-US/docs/Web/CSS/touch-action */
|
||||||
touch-action: none;
|
touch-action: pan-y;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
-webkit-user-select: none;
|
-webkit-user-select: none;
|
||||||
-moz-user-select: none;
|
-moz-user-select: none;
|
||||||
|
@ -123,17 +123,21 @@ export function useDndHandlers (index) {
|
|||||||
if (isTouchDragging) {
|
if (isTouchDragging) {
|
||||||
// Find the element under the touch point
|
// Find the element under the touch point
|
||||||
const elementUnderTouch = document.elementFromPoint(touch.clientX, touch.clientY)
|
const elementUnderTouch = document.elementFromPoint(touch.clientX, touch.clientY)
|
||||||
if (elementUnderTouch) {
|
if (!elementUnderTouch) {
|
||||||
|
return dispatch({ type: DRAG_LEAVE })
|
||||||
|
}
|
||||||
|
|
||||||
const element = elementUnderTouch.closest('[data-index]')
|
const element = elementUnderTouch.closest('[data-index]')
|
||||||
if (element) {
|
if (!element) {
|
||||||
|
return dispatch({ type: DRAG_LEAVE })
|
||||||
|
}
|
||||||
|
|
||||||
const elementIndex = parseInt(element.dataset.index)
|
const elementIndex = parseInt(element.dataset.index)
|
||||||
if (elementIndex !== index) {
|
if (elementIndex !== index) {
|
||||||
dispatch({ type: DRAG_ENTER, index: elementIndex })
|
dispatch({ type: DRAG_ENTER, index: elementIndex })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [touchStartX, touchStartY, isTouchDragging, index, dispatch])
|
}, [touchStartX, touchStartY, isTouchDragging, index, dispatch])
|
||||||
|
|
||||||
const handleTouchEnd = useCallback((e) => {
|
const handleTouchEnd = useCallback((e) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user