Skip to content

fix: preserve nested first-child drop target - #1070

Merged
yoyo837 merged 1 commit into
react-component:masterfrom
nrps9909:codex/fix-nested-first-child-drop
Aug 27, 2026
Merged

fix: preserve nested first-child drop target#1070
yoyo837 merged 1 commit into
react-component:masterfrom
nrps9909:codex/fix-nested-first-child-drop

Conversation

@nrps9909

@nrps9909 nrps9909 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Summary

  • preserve the hovered first child as the drop target when inserting before it inside an expanded parent
  • return the nested child through onDrop.node with dropToGap=true and the correct relative position
  • cover both LTR and RTL drag geometry, including the allowDrop contract

Problem

When the pointer enters the upper half of the first child of an expanded node, calcDropPosition currently replaces that child with the previous flattened node, which is its parent. Dropping a sibling before that first child therefore reports the parent with an inside drop instead of the child with a gap drop.

The root-level special case does not cover nested first children. Simply removing its level guard is insufficient because the target has already been replaced by the parent.

Solution

Detect the first-child upper-half case before the flattened-node fallback. This keeps the real hovered child as the abstract drop target, then reuses the existing before-target and allowDrop({ dropPosition: -1 }) path.

Close ant-design/ant-design#59099.

Verification

  • exact base regression: failed in both LTR and RTL with actual node 0-0, dropToGap=false, dropPosition=0
  • focused TreeDraggable.spec.tsx: 38/38 passed
  • full test suite: 226/226 passed, 42/42 snapshots
  • TypeScript: passed
  • ESLint: 0 errors (11 existing warnings)
  • Prettier: passed
  • ESM/CJS compile: passed
  • git diff --check: passed

I checked current open rc-tree PRs and found no duplicate implementation. The existing target-file overlaps are unrelated broad or stale changes.

AI assistance disclosure: Codex assisted with source tracing, the exact-base reproduction, implementation, validation, duplicate screening, and this description. The behavior and final diff were verified locally.

Summary by CodeRabbit

  • Bug 修复

    • 优化树形拖拽放置判断,修复拖动到已展开节点首个子节点上方时的放置位置问题。
    • 改进从左到右和从右到左布局下的拖放行为,确保目标节点与放置位置信息正确传递。
  • 测试

    • 新增相关拖拽场景测试,覆盖间隙放置及放置位置校验。
@vercel

vercel Bot commented Aug 26, 2026

Copy link
Copy Markdown

@nrps9909 is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d5e247f6-235b-44f5-834e-3406b57bb27d

📥 Commits

Reviewing files that changed from the base of the PR and between 2492cbc and 9d6351d.

📒 Files selected for processing (2)
  • src/util.tsx
  • tests/TreeDraggable.spec.tsx

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


Walkthrough

拖放逻辑新增 dropBeforeTarget 判断。根层首节点不再错误回退到前一个节点。LTR 与 RTL 测试覆盖展开节点首个子节点顶部的间隙放置,并验证 dropPosition: -1

Changes

拖放位置处理

Layer / File(s) Summary
目标前方放置与验证
src/util.tsx, tests/TreeDraggable.spec.tsx
新增 dropBeforeTarget 标志。目标位于上半部且不是根层首节点时,逻辑才回退到前一个节点。首个根节点复用该标志处理 dropPosition = -1。LTR 与 RTL 测试验证 onDropallowDrop 收到目标节点及位置 -1

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 9d635

This localized fix preserves the correct nested first-child drop target and adds regression coverage for LTR and RTL behavior; no actionable merge-blocking risk remains after normal checks and review.

Poem

小兔拖着树枝跑
目标上方留个槽
首节点前不乱跳
LTR、RTL 都对好
回调带着位置号

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了本次修复的主要变更,即保留嵌套首个子节点作为拖放目标。
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.84%. Comparing base (2492cbc) to head (9d6351d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1070      +/-   ##
==========================================
- Coverage   99.84%   99.84%   -0.01%     
==========================================
  Files          15       15              
  Lines        1319     1318       -1     
  Branches      400      390      -10     
==========================================
- Hits         1317     1316       -1     
  Misses          2        2              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@yoyo837
yoyo837 merged commit f20de02 into react-component:master Aug 27, 2026
9 of 10 checks passed
aibayanyu20 added a commit to antdv-next/vue-components that referenced this pull request Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants