Skip to content

Commit 0391e62

Browse files
author
Clauderic Demers
committed
fix: issue with windowAsScrollContainer and translation offsets
With the recently introduced change to automatically find the scrolling parent of the SortableContainer (getScrollingParent function), there was an issue introduced where the scrollContainer would resolve to the document.body when using windowAsScrollContainer, and the container scroll offset would be taken into account twice. Normally, we take into account the window scroll position and the scroll container’s scroll position, but in this case they were both the same element.
1 parent 5f59938 commit 0391e62

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/SortableContainer/index.js

+22-8
Original file line numberDiff line numberDiff line change
@@ -502,20 +502,14 @@ export default function sortableContainer(
502502

503503
animateNodes() {
504504
const {transitionDuration, hideSortableGhost, onSortOver} = this.props;
505+
const {containerScrollDelta, windowScrollDelta} = this;
505506
const nodes = this.manager.getOrderedRefs();
506-
const containerScrollDelta = {
507-
left: this.scrollContainer.scrollLeft - this.initialScroll.left,
508-
top: this.scrollContainer.scrollTop - this.initialScroll.top,
509-
};
510507
const sortingOffset = {
511508
left:
512509
this.offsetEdge.left + this.translate.x + containerScrollDelta.left,
513510
top: this.offsetEdge.top + this.translate.y + containerScrollDelta.top,
514511
};
515-
const windowScrollDelta = {
516-
left: window.pageXOffset - this.initialWindowScroll.left,
517-
top: window.pageYOffset - this.initialWindowScroll.top,
518-
};
512+
519513
const prevIndex = this.newIndex;
520514
this.newIndex = null;
521515

@@ -745,5 +739,25 @@ export default function sortableContainer(
745739

746740
return this.props.helperContainer || this.document.body;
747741
}
742+
743+
get containerScrollDelta() {
744+
const {useWindowAsScrollContainer} = this.props;
745+
746+
if (useWindowAsScrollContainer) {
747+
return {left: 0, top: 0};
748+
}
749+
750+
return {
751+
left: this.scrollContainer.scrollLeft - this.initialScroll.left,
752+
top: this.scrollContainer.scrollTop - this.initialScroll.top,
753+
};
754+
}
755+
756+
get windowScrollDelta() {
757+
return {
758+
left: this.contentWindow.pageXOffset - this.initialWindowScroll.left,
759+
top: this.contentWindow.pageYOffset - this.initialWindowScroll.top,
760+
};
761+
}
748762
};
749763
}

0 commit comments

Comments
 (0)