SortableJS / Sortable

Reorderable drag-and-drop lists for modern browsers and touch devices. No jQuery or framework required.
https://sortablejs.github.io/Sortable/
MIT License
29.78k stars 3.7k forks source link

[bug] Scrolling up shows placeholder which causes browser to scrolldown until the element passes the placeholder #2200

Open alexandrum2k opened 2 years ago

alexandrum2k commented 2 years ago

Describe the bug Scrolling behaviour sluggish when auto scroll is active and force fallback is true. When scrolling up, the placeholder appears after hovering on each element and that causes the browser to scroll bottom x pixels where x pixels = palceholder height

To Reproduce Steps to reproduce the behavior:

1) Create a sortable instance using settings: scroll: true, forceAutoscrollFallback: true, pull: false, ghostClass: 'block-sort-highlight', dragoverBubble: false, animation: 150, removeCloneOnHide: true, scrollSensitivity: 200, scrollSpeed: 160, bubbleScroll: true

2) create a list of 6 items that can be sorted, with a height of 300px each 3) set placeholder height to 100px (block-sort-highlight) 4) move the first element to the end of the list, using autoscroll feature - it works fine 5) move the last element to the start of the list, using autoscroll feature - everytime the drag item hovers over another item, the placeholder appears and the browser scrolls down 100px (height of placeholder)

Expected behavior Scrolling should delay the placeholder show() until the browser stops scrolling

Information

Versions - Look in your package.json for this information: sortablejs = 1.15.0 @types/sortablejs = 1.15.0

raphaeldealmeida commented 1 year ago

I noticed that it only happens in Firefox. Any way to avoid this unwanted scroll?

raphaeldealmeida commented 1 year ago

I got a temporary solution.

onStart = () => {
  if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
    let scrollTop = window.pageYOffset || document.documentElement.scrollTop
    let scrollLeft = window.pageXOffset || document.documentElement.scrollLeft

    window.onscroll = () => window.scrollTo(scrollLeft, scrollTop)
  }
}

onEnd = () => {
              window.onscroll = () => { }
          }