-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DnD for both node reordering and drop as child #181
Comments
Thank you. You are correct in that this isn't possible with the code today. This was the most useful write up of the problem though, thank you. |
I don't know if I would describe this as "works fine". Index 0 is opinionated. Maybe I want to add it as the last child. |
It doesn't seem to have changed anything. With all of the nodes having an empty child list, I can still drop as a sibling if the node is closed, but if the node is open it will try and add it as a child. Dropping on the node will also add as a child, as expected. |
@rmapes I met the same problem with you. After some digging, I realize that #202 indeed solves the problem. Watch the demo video closely: However, this is really bad experience for users. I've figured a better approach: make node with empty children closed by default, then if the drop cursor is below the node, the drop will always be sibling, and if the drop cursor is above the node, the drop will be a child. This should be a intuitive way for users. My pesdo code: const Node = ({node}) => {
useMount(() => {
if (node.children.length === 0) {
node.close()
} else {
node.open()
}
})
return <div className="node">...</div>
}
const App = () => {
return <Tree ...>{Node}</Tree>
}
|
I would like to render the tree where each node can be at an arbitrary place in the hierarchy and dropping a node on another node makes it a child of that node.
I would also like to be able to reorder children by dragging within the child list.
At the moment, if I make all of the nodes internal nodes (i.e. they all have a child list which may be empty), then dropping a node on another node works fine (calls onMove with the target node as parent and an index of 0). However, dropping a node after another node also returns that node as a parent with an index of 0, unless the node both has children and is closed. This means that I can't implement the move behaviour consistently.
On the other hand, if I make all nodes with no children leaf nodes (by setting children to null if it is an empty array), I get the correct move behaviour (parent is parent of group and index is order within children) but I can no longer drop on the leaf nodes to create a child.
The text was updated successfully, but these errors were encountered: