Fix reorder autoscroll on scrollable pages by mattgperry · Pull Request #3481 · motiondivision/motion · GitHub
Skip to content

Fix reorder autoscroll on scrollable pages - #3481

Merged
mattgperry merged 3 commits into
mainfrom
claude/fix-reorder-autoscroll-VMQKK
Jan 20, 2026
Merged

mattgperry merged 3 commits into
mainfrom
claude/fix-reorder-autoscroll-VMQKK

Conversation

@mattgperry

@mattgperry mattgperry commented Jan 19, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #3469

When the Reorder component is used on a scrollable page (without an
explicit overflow: auto/scroll container), the autoscroll feature
was not working because findScrollableAncestor only looked for
elements with overflow: auto/scroll CSS properties.

This fix adds support for page-level scrolling by:
1. Detecting when the document itself is scrollable (scrollHeight >
   innerHeight)
2. Using window.scrollBy() for page-level scrolling when no scrollable
   ancestor is found
3. Calculating scroll thresholds based on viewport dimensions instead
   of element bounds

Fixes #3469
The core fix: clamp the scrollable container's bounds to the viewport
when calculating distance from edges. Previously, if a container's
bottom was at y=800 but the viewport ended at y=600, dragging to
y=580 wouldn't trigger autoscroll because distanceFromEnd was 220px
(well above the 50px threshold).

Now we use:
- start = max(0, rect.top)
- end = min(viewportSize, rect.bottom)

This ensures autoscroll triggers when near the *visible* edge of the
container, regardless of whether the page is scrollable.

Also added support for page-level scrolling (using window.scrollBy)
when there's no scrollable container but the page itself is scrollable.

Fixes #3469
The gesture system uses pageX/pageY coordinates (from extractEventInfo
in event-info.ts), but getBoundingClientRect() returns viewport-relative
coordinates. When the page is scrolled, these coordinate systems don't
match, causing autoscroll to fail.

For example, if the page is scrolled 500px:
- pointerPosition (pageY) = 800
- rect.top (viewport) = 200
- distanceFromStart = 600 (way above 50px threshold)

The fix converts the pointer position to viewport coordinates by
subtracting the page scroll offset before comparing with rect bounds.

Fixes #3469
@mattgperry mattgperry changed the title Fix drag gesture after context menu opens Fix reorder autoscroll on scrollable pages Jan 19, 2026
@claude

claude Bot commented Jan 19, 2026

Copy link
Copy Markdown

@mattgperry
mattgperry merged commit 5d3ab70 into main Jan 20, 2026
4 checks passed
@mattgperry
mattgperry deleted the claude/fix-reorder-autoscroll-VMQKK branch January 20, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Reorder does not work as expected in a scrollable page

2 participants