Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/SortableContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
isTouchEvent,
provideDisplayName,
omit,
getScrollingParent,
} from '../utils';

export default function sortableContainer(
Expand Down Expand Up @@ -145,9 +146,10 @@ export default function sortableContainer(

this.contentWindow =
typeof contentWindow === 'function' ? contentWindow() : contentWindow;

this.scrollContainer = useWindowAsScrollContainer
? this.document.scrollingElement || this.document.documentElement
: this.container;
: getScrollingParent(this.container) || this.container;

for (const key in this.events) {
if (this.events.hasOwnProperty(key)) {
Expand Down Expand Up @@ -318,7 +320,7 @@ export default function sortableContainer(

const margin = getElementMargin(node);

const containerBoundingRect = this.container.getBoundingClientRect();
const containerBoundingRect = this.scrollContainer.getBoundingClientRect();
const dimensions = getHelperDimensions({index, node, collection});

this.node = node;
Expand All @@ -341,8 +343,8 @@ export default function sortableContainer(
this.offsetEdge = getEdgeOffset(node, this.container);
this.initialOffset = getPosition(event);
this.initialScroll = {
top: this.container.scrollTop,
left: this.container.scrollLeft,
top: this.scrollContainer.scrollTop,
left: this.scrollContainer.scrollLeft,
};

this.initialWindowScroll = {
Expand Down Expand Up @@ -587,8 +589,8 @@ export default function sortableContainer(
const {transitionDuration, hideSortableGhost, onSortOver} = this.props;
const nodes = this.manager.getOrderedRefs();
const containerScrollDelta = {
left: this.container.scrollLeft - this.initialScroll.left,
top: this.container.scrollTop - this.initialScroll.top,
left: this.scrollContainer.scrollLeft - this.initialScroll.left,
top: this.scrollContainer.scrollTop - this.initialScroll.top,
};
const sortingOffset = {
left:
Expand Down
20 changes: 20 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,23 @@ export function getLockPixelOffset({lockOffset, width, height}) {
y: offsetY,
};
}

function isScrollable(el) {
const computedStyle = window.getComputedStyle(el);
const overflowRegex = /(auto|scroll)/;
const properties = ['overflow', 'overflowX', 'overflowY'];

return properties.find((property) =>
overflowRegex.test(computedStyle[property]),
);
}

export function getScrollingParent(el) {
if (!el) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might need to be !(el instanceof HTMLElement)

return null;
} else if (isScrollable(el)) {
return el;
} else {
return getScrollingParent(el.parentNode);
}
}