1

I have a LWC component with a lightning-tree for role hierarchy. I need to implement a drag and drop function for the items to reorder them and save the new hierarchy.

This is the tree:

<lightning-tree items={items} onselect={handleSelectAssign}></lightning-tree>

How it looks:

enter image description here

Is it possible to drag and drop the items?

Best regards, Renato

1 Answer 1

2

This won't be possible with Salesforce's lightning-data-tree. We can't "see" the internal structure of components, either our own or those in another namespace. The shadow root for each component acts as a membrane that restricts access to the internal structure. The best you can do here is to have the user select a node, click a button, then select the other node.

Fortunately, you can swap out your current code and use the tree and treeItem components found in the base-components-recipes library or by grabbing the source code from the lightning-base-components npm module. This will mean, however, that you'll have to maintain your own separate copy of the tree and treeItem components.

Not the answer you're looking for? Browse other questions tagged .