react-sortable-hoc icon indicating copy to clipboard operation
react-sortable-hoc copied to clipboard

useWindowAsScrollContainer should not crawl to root node

Open knarkunas opened this issue 7 years ago • 3 comments

There is an issue with grid and useWindowAsScrollContainer. It should not be crawling up to first overflow: scroll|auto DOM element. As seen in getScrollingParent(this.container). Result is something like this using grid layout: image_sort_bug_known image_sort_bug_example

Or we could get a prop of some sort for grid layout when scroll is not used at all? Like isScrollable and then this code:

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

becomes

if (isScrollable) {
     this.scrollContainer = useWindowAsScrollContainer
               ? this.document.scrollingElement || this.document.documentElement
               : getScrollingParent(this.container) || this.container;
} else {
      this.scrollContainer = this.container;
}

Currently animateNodes inside SortableContainer.js does transformation and calculation ends up this.containerBoundingRect having to be root element (most websites has overflow scroll somewhere, right?). edgeOffset.left + translate.x > this.containerBoundingRect.width - offset.width

Current workaround, if you want to have non scrollable, simple grid box layout and draggable list is to add <div style={{ overflow: 'auto' }}> around your SortableContainer. And do not forget to set useWindowAsScrollContainer to false.

Example to reproduce: https://codesandbox.io/s/serene-dawn-rwpj0

Commit that might be affecting this issue: https://github.com/clauderic/react-sortable-hoc/pull/507

knarkunas avatar Jul 25 '19 04:07 knarkunas

Possible other issues related to this one: https://github.com/clauderic/react-sortable-hoc/issues/551 https://github.com/clauderic/react-sortable-hoc/issues/523 https://github.com/clauderic/react-sortable-hoc/issues/520

knarkunas avatar Jul 25 '19 04:07 knarkunas

It began with version 1.8.0. Before this, in version 1.7.1, the parent container was simply taken for the calculation.

const containerBoundingRect = this.container.getBoundingClientRect();

zalevsk1y avatar Jul 25 '19 08:07 zalevsk1y

Thanks knarkunas! Your workaround saved my day. It's the 'overflow: auto' that did the trick. I didn't have to set useWindowAsScrollContainer to false.

Mathieu-DA avatar Sep 11 '19 09:09 Mathieu-DA