Skip to content

fix: prefer ancestor drop target over nearest-by-distance in DragManager#10170

Merged
snowystinger merged 2 commits into
adobe:mainfrom
mvanhorn:fix/10055-dnd-findnearestdroptarget-ancestor
Jun 26, 2026
Merged

fix: prefer ancestor drop target over nearest-by-distance in DragManager#10170
snowystinger merged 2 commits into
adobe:mainfrom
mvanhorn:fix/10055-dnd-findnearestdroptarget-ancestor

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Drag and drop now prefers an ancestor drop target over a closer-by-distance sibling, matching how nested drop zones are expected to resolve.

Why this matters

Reported in #10055: findNearestDropTarget picked the geometrically nearest target, so a small drop zone next to a containing one could win even when the pointer was inside the container. The fix prefers an ancestor target when the pointer is within it, before falling back to nearest-by-distance.

Changes

  • Adjust DragManager's target selection to prefer an ancestor drop target containing the pointer.

Testing

Added a DnD test covering the nested-target case.

Fixes #10055

AI was used for assistance.

@snowystinger snowystinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, reviewers will want to pull it down and copy the codesandbox into our storybook to verify as well.
I'll hopefully have some time to try it tomorrow.

@snowystinger snowystinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Verified locally, thank you!

@snowystinger snowystinger added the small review Easy to review PR label Jun 25, 2026
@devongovett

Copy link
Copy Markdown
Member

One thing to note is that this doesn't necessarily select the deepest ancestor in case there are multiple. But seems like an improvement.

@snowystinger snowystinger added this pull request to the merge queue Jun 26, 2026
Merged via the queue into adobe:main with commit d52472c Jun 26, 2026
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useDragAndDrop keyboard DnD: findNearestDropTarget selects wrong collection when drag source is last item

3 participants