Skip to content
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

feat(RAC): Tree drag and drop #7692

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open

Conversation

rob-clayburn
Copy link
Contributor

I'm looking to get some feedback on this PR to add drag and drop to the Tree.

I am really really new to this codebase, and there are probably a ton of things I've not understood and have messed up

I've mainly just copied the logic from the listbox and applied it to the tree component.

There's a storybook story which I've added at http://localhost:9003/?path=/story/treeview--tree-example-dynamic-drag-n-drop&providerSwitcher-express=false&strict=true

Some things that would be great to get some feedback/help on are:

  • I'm unclear as to whether the dragAndDropHooks should be created by the user each time (e.g. in the story). Some things i can see being useful, but it feels like the reorder function shouldn't have to be implemented here. Is there a better place to put this?

  • Re-ordering works, but at some point it stops working. I can't seem to find a repeatable pattern of drag / drops to consistently replicate this though.

  • In storybook the hot reload gives an error:
    image

  • Although I've added the keyboard code - I've not yet tested that - was hoping to get the other issues ironed out first.

  • The way I've implemented the drop insert indicator causes the tree items to move which in turn can cause the drop to switch from before to after. The droppable listbox story renders items with a gap in between but I'm not sure if that is what is wanted in a tree view.

@reidbarber
Copy link
Member

Thanks for the PR! I'm going to be taking a closer look when I have some time soon, just wanted to leave an update.

@rob-clayburn
Copy link
Contributor Author

thanks, have you managed to carve out some time to look at this?

@reidbarber
Copy link
Member

Sorry for the delay, we've been busy with the latest release! I just pushed a few small updates and a story that has DnD working in RAC Tree. I still need to debug RSP TreeView and fix some merge conflicts. The state management in the story should get simplified once we merge #7854.

@reidbarber
Copy link
Member

Pushed a few changes so it should be in a decent state to test out. Some things to note:

  • We're going to scope this to Tree in React Aria Components for now (adding to React Spectrum TreeView can be a follow-up). I made a new story for this and removed the old one.
  • We'll probably need a way expand/collapse items while keyboard navigating during a drop.

@@ -234,10 +235,29 @@ export function useTreeData<T extends object>(options: TreeOptions<T>): TreeData
}
}

function getDescendantKeys(node?: TreeNode<T>): Key[] {
Copy link
Member

Choose a reason for hiding this comment

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

any reason to have node be optional? can we make it required?

if (!node) {
return descendantKeys;
}
function recurse(currentNode: TreeNode<T>) {
Copy link
Member

Choose a reason for hiding this comment

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

does the traversal order matter? preorder, in order, postorder

should descendantKeys be a Set if it doesn't matter?

disabledKeys: state.selectionManager.disabledKeys,
disabledBehavior: state.selectionManager.disabledBehavior,
layout: 'stack',
direction,
Copy link
Member

Choose a reason for hiding this comment

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

I noticed that Table in RAC doesn't specify direction is that a bug? or what does this affect?

@reidbarber reidbarber changed the title [WIP] Tree drag and drop feat(RAC): Tree drag and drop Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🏗 In Progress
Development

Successfully merging this pull request may close these issues.

3 participants