Skip to content

Support scroll adjusted transform#2073

Open
jindong-zhannng wants to merge 7 commits into
clauderic:mainfrom
jindong-zhannng:feat/scroll-adjusted-transform
Open

Support scroll adjusted transform#2073
jindong-zhannng wants to merge 7 commits into
clauderic:mainfrom
jindong-zhannng:feat/scroll-adjusted-transform

Conversation

@jindong-zhannng

Copy link
Copy Markdown

Close #2069

Port scroll-adjusted translate functionality from legacy dnd-kit:

  • Listen to scroll event to measure the scroll delta with the same algorithm as legacy implementation.
  • Add dragOperation.adjustedTransform.
  • Dispatch virtual dragmove event when scrolling.

@changeset-bot

changeset-bot Bot commented May 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6cc8f63

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 10 packages
Name Type
@dnd-kit/abstract Minor
@dnd-kit/dom Minor
@dnd-kit/collision Minor
@dnd-kit/helpers Minor
@dnd-kit/react Minor
@dnd-kit/solid Minor
@dnd-kit/svelte Minor
@dnd-kit/vue Minor
@dnd-kit/geometry Minor
@dnd-kit/state Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@clauderic clauderic added feature request abstract Abstract package dom DOM package labels May 28, 2026

@clauderic clauderic left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Summary

Adds a new ScrollCompensator core plugin to @dnd-kit/dom and a scrollAdjustment / adjustedTransform field on DragOperation, restoring the scroll-adjusted delta semantics from the legacy @dnd-kit/core. While dragging, the plugin listens for scroll events on the source's owner document, filters to the source's scrollable ancestors, accumulates the delta against the initial scroll offsets, and dispatches a virtual: true move so listeners see the updated transform. Closes #2069.

Feedback

Suggestions

  • packages/abstract/src/core/manager/operation.ts:182get adjustedTransform() is decorated @derived but has a write side-effect (this.#adjustedTransform = result). The whole purpose of #adjustedTransform is to keep snapshot() in sync, but it only updates when something reads the getter. The disposeAdjustedTransformEffect in ScrollCompensator.ts exists solely to force a read on every reactive change. That's two indirections to achieve what could be one line in snapshot():
    adjustedTransform: {
      x: this.#transform.x + this.scrollAdjustment.x,
      y: this.#transform.y + this.scrollAdjustment.y,
    },
    This would let you drop both the #adjustedTransform cache and the second effect in the plugin. Worth simplifying before this lands — the current shape will be confusing to future readers.
  • packages/dom/src/core/plugins/scrolling/ScrollCompensator.ts:60manager.actions.move({event, virtual: true}) dispatches dragmove with the scroll event as the nativeEvent. Consumers that branch on nativeEvent type (e.g. distinguishing pointer/keyboard) will see an unexpected ScrollEvent. Consider documenting this in the JSDoc for the virtual option in actions.ts, or pass event: undefined if the scroll event is not semantically meaningful here.
  • packages/dom/src/core/plugins/scrolling/ScrollCompensator.ts:43initial is captured the first time the effect runs (when dragging flips true). If the source's scrollableAncestors change during a drag (e.g. the DOM structure shifts), neither the ancestor set nor initial are recomputed. Probably fine in practice — flagging in case it's intentional.
  • No tests cover ScrollCompensator or adjustedTransform behavior. The legacy delta semantics were subtle (scroll inside the drag would update delta even without pointer movement) — a bun:test that starts a drag, simulates a scroll event on an ancestor, and asserts the dispatched dragmove carries the expected adjustedTransform would catch regressions.

Changeset

  • Status: present and correct ('@dnd-kit/abstract': minor, '@dnd-kit/dom': minor). Minor is right for a new public field/plugin export, pre-1.0.

Overall

Thanks @jindong-zhannng — this is a thoughtful port of a feature that legacy users definitely rely on, and the docs update on drag-drop-manager.mdx is a nice touch. The main thing I'd ask for is simplifying the adjustedTransform plumbing so the cache and forcing-effect go away, plus a small test.


[claude-review]

@jindong-zhannng jindong-zhannng force-pushed the feat/scroll-adjusted-transform branch from 886f679 to e2abe6b Compare June 1, 2026 08:20
@jindong-zhannng

Copy link
Copy Markdown
Author

Simplified dragOperation.adjustedTransform and added unit tests.

@jindong-zhannng jindong-zhannng requested a review from clauderic June 2, 2026 02:20
@jindong-zhannng jindong-zhannng force-pushed the feat/scroll-adjusted-transform branch from e2abe6b to 69891d0 Compare June 16, 2026 11:18
@jindong-zhannng

Copy link
Copy Markdown
Author

Hi @clauderic , can we move forward this PR?

@jindong-zhannng jindong-zhannng force-pushed the feat/scroll-adjusted-transform branch from 9954509 to 6cc8f63 Compare June 25, 2026 03:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

abstract Abstract package dom DOM package feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Support scroll adjusted translate

2 participants