react-component / react-component/tree

onDrop's arguments dropPosition not equal allowDrop's arguments dropPosition

Open
#654 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.3k
Forks
490
Avg merge
3d 17h
Merged PRs (30d)
5

Description

import RcTree from "rc-tree";
import "rc-tree/assets/index.css";

const treeData = [
  {
    title: "title0",
    key: "key0"
  },
  {
    title: "title1",
    key: "key1"
  },
  {
    title: "title2",
    key: "key2"
  },
  {
    title: "title3",
    key: "key3"
  },
  {
    title: "title4",
    key: "key4"
  },
  {
    title: "title5",
    key: "key5",
    children: [
      {
        title: "title4-0",
        key: "key4-0"
      },
      {
        title: "title4-1",
        key: "key4-1"
      },
      {
        title: "title4-2",
        key: "key4-2"
      },
      {
        title: "title4-3",
        key: "key4-3"
      }
    ]
  },
  {
    title: "title6",
    key: "key6"
  }
];

export default function App() {
  return (
    <RcTree
      allowDrop={(params) => {
        if (Math.random() > 0.99) {
          console.log("allow drop:", params);
        }
        return true;
      }}
      onDrop={(params) => {
        console.log("on Drop:", params);
      }}
      draggable
      defaultExpandAll
      treeData={treeData}
    />
  );
}

quick codesandbox

try to drag title4-3 as first child(before title4-0), and see console

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction and compare the parameters logged by allowDrop and onDrop while dragging title4-3 before title4-0. Trace the drag-and-drop entry point used by RcTree, then verify that both callbacks report the same dropPosition for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.