Skip to content

Commit 106727d

Browse files
author
Clauderic Demers
committed
Fix scrolling issues on mobile with anchor tag elements
1 parent ea3edeb commit 106727d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/SortableContainer/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
getElementMargin,
1414
getLockPixelOffset,
1515
getPosition,
16+
isTouchEvent,
1617
provideDisplayName,
1718
omit,
1819
} from '../utils';
@@ -182,7 +183,7 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
182183
* prevent subsequent 'mousemove' events from being fired
183184
* (see https://github.com/clauderic/react-sortable-hoc/issues/118)
184185
*/
185-
if (event.target.tagName.toLowerCase() === 'a') {
186+
if (!isTouchEvent(event) && event.target.tagName.toLowerCase() === 'a') {
186187
event.preventDefault();
187188
}
188189

@@ -748,7 +749,7 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
748749
config.withRef,
749750
'To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableContainer() call'
750751
);
751-
752+
752753
return this.refs.wrappedInstance;
753754
}
754755

src/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ export function getPosition(event) {
102102
}
103103
}
104104

105+
export function isTouchEvent(event) {
106+
return (
107+
event instanceof TouchEvent ||
108+
event.touches && event.touches.length ||
109+
event.changedTouches && event.changedTouches.length
110+
);
111+
}
112+
105113
export function getEdgeOffset(node, parent, offset = {top: 0, left: 0}) {
106114
// Get the actual offsetTop / offsetLeft value, no matter how deep the node is nested
107115
if (node) {

0 commit comments

Comments
 (0)