@@ -144,8 +144,8 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
144
144
145
145
this . _touched = true ;
146
146
this . _pos = {
147
- x : e . clientX ,
148
- y : e . clientY ,
147
+ x : e . pageX ,
148
+ y : e . pageY ,
149
149
} ;
150
150
151
151
const node = closest ( e . target , el => el . sortableInfo != null ) ;
@@ -197,8 +197,8 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
197
197
198
198
if ( ! this . state . sorting && this . _touched ) {
199
199
this . _delta = {
200
- x : this . _pos . x - e . clientX ,
201
- y : this . _pos . y - e . clientY ,
200
+ x : this . _pos . x - e . pageX ,
201
+ y : this . _pos . y - e . pageY ,
202
202
} ;
203
203
const delta = Math . abs ( this . _delta . x ) + Math . abs ( this . _delta . y ) ;
204
204
@@ -271,6 +271,11 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
271
271
left : this . scrollContainer . scrollLeft ,
272
272
} ;
273
273
274
+ this . initialWindowScroll = {
275
+ top : window . scrollY ,
276
+ left : window . scrollX ,
277
+ } ;
278
+
274
279
const fields = node . querySelectorAll ( 'input, textarea, select' ) ;
275
280
const clonedNode = node . cloneNode ( true ) ;
276
281
const clonedFields = [
@@ -443,8 +448,8 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
443
448
444
449
getOffset ( e ) {
445
450
return {
446
- x : e . touches ? e . touches [ 0 ] . clientX : e . clientX ,
447
- y : e . touches ? e . touches [ 0 ] . clientY : e . clientY ,
451
+ x : e . touches ? e . touches [ 0 ] . pageX : e . pageX ,
452
+ y : e . touches ? e . touches [ 0 ] . pageY : e . pageY ,
448
453
} ;
449
454
}
450
455
@@ -508,11 +513,16 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
508
513
509
514
updatePosition ( e ) {
510
515
const { lockAxis, lockToContainerEdges} = this . props ;
516
+
511
517
const offset = this . getOffset ( e ) ;
512
518
const translate = {
513
519
x : offset . x - this . initialOffset . x ,
514
520
y : offset . y - this . initialOffset . y ,
515
521
} ;
522
+ // Adjust for window scroll
523
+ translate . y -= ( window . scrollY - this . initialWindowScroll . top ) ;
524
+ translate . x -= ( window . scrollX - this . initialWindowScroll . left ) ;
525
+
516
526
this . translate = translate ;
517
527
518
528
if ( lockToContainerEdges ) {
@@ -560,6 +570,10 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
560
570
left : this . offsetEdge . left + this . translate . x + deltaScroll . left ,
561
571
top : this . offsetEdge . top + this . translate . y + deltaScroll . top ,
562
572
} ;
573
+ const scrollDifference = {
574
+ top : ( window . scrollY - this . initialWindowScroll . top ) ,
575
+ left : ( window . scrollX - this . initialWindowScroll . left ) ,
576
+ } ;
563
577
this . newIndex = null ;
564
578
565
579
for ( let i = 0 , len = nodes . length ; i < len ; i ++ ) {
@@ -571,6 +585,7 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
571
585
width : this . width > width ? width / 2 : this . width / 2 ,
572
586
height : this . height > height ? height / 2 : this . height / 2 ,
573
587
} ;
588
+
574
589
const translate = {
575
590
x : 0 ,
576
591
y : 0 ,
@@ -619,9 +634,9 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
619
634
if (
620
635
index < this . index &&
621
636
(
622
- ( sortingOffset . left - offset . width <= edgeOffset . left &&
623
- sortingOffset . top <= edgeOffset . top + offset . height ) ||
624
- sortingOffset . top + offset . height <= edgeOffset . top
637
+ ( ( sortingOffset . left + scrollDifference . left ) - offset . width <= edgeOffset . left &&
638
+ ( sortingOffset . top + scrollDifference . top ) <= edgeOffset . top + offset . height ) ||
639
+ ( sortingOffset . top + scrollDifference . top ) + offset . height <= edgeOffset . top
625
640
)
626
641
) {
627
642
// If the current node is to the left on the same row, or above the node that's being dragged
@@ -643,9 +658,9 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
643
658
} else if (
644
659
index > this . index &&
645
660
(
646
- ( sortingOffset . left + offset . width >= edgeOffset . left &&
647
- sortingOffset . top + offset . height >= edgeOffset . top ) ||
648
- sortingOffset . top + offset . height >= edgeOffset . top + height
661
+ ( ( sortingOffset . left + scrollDifference . left ) + offset . width >= edgeOffset . left &&
662
+ ( sortingOffset . top + scrollDifference . top ) + offset . height >= edgeOffset . top ) ||
663
+ ( sortingOffset . top + scrollDifference . top ) + offset . height >= edgeOffset . top + height
649
664
)
650
665
) {
651
666
// If the current node is to the right on the same row, or below the node that's being dragged
@@ -666,13 +681,13 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
666
681
} else {
667
682
if (
668
683
index > this . index &&
669
- sortingOffset . left + offset . width >= edgeOffset . left
684
+ ( sortingOffset . left + scrollDifference . left ) + offset . width >= edgeOffset . left
670
685
) {
671
686
translate . x = - ( this . width + this . marginOffset . x ) ;
672
687
this . newIndex = index ;
673
688
} else if (
674
689
index < this . index &&
675
- sortingOffset . left <= edgeOffset . left + offset . width
690
+ ( sortingOffset . left + scrollDifference . left ) <= edgeOffset . left + offset . width
676
691
) {
677
692
translate . x = this . width + this . marginOffset . x ;
678
693
if ( this . newIndex == null ) {
@@ -683,13 +698,13 @@ export default function sortableContainer(WrappedComponent, config = {withRef: f
683
698
} else if ( this . axis . y ) {
684
699
if (
685
700
index > this . index &&
686
- sortingOffset . top + offset . height >= edgeOffset . top
701
+ ( sortingOffset . top + scrollDifference . top ) + offset . height >= edgeOffset . top
687
702
) {
688
703
translate . y = - ( this . height + this . marginOffset . y ) ;
689
704
this . newIndex = index ;
690
705
} else if (
691
706
index < this . index &&
692
- sortingOffset . top <= edgeOffset . top + offset . height
707
+ ( sortingOffset . top + scrollDifference . top ) <= edgeOffset . top + offset . height
693
708
) {
694
709
translate . y = this . height + this . marginOffset . y ;
695
710
if ( this . newIndex == null ) {
0 commit comments