Skip to content

Commit 3bd0909

Browse files
committed
Provide the path and treeIndex of the moved node in onMoveNode
1 parent 4ef28b6 commit 3bd0909

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ searchFocusOffset | number | | | Ou
5656
searchFinishCallback | func | | | Get the nodes that match the search criteria. Used for counting total matches, etc.<div>`(matches: { node: object, path: number[] or string[], treeIndex: number }[]): void`</div>
5757
generateNodeProps | func | | | Generate an object with additional props to be passed to the node renderer. Use this for adding buttons via the `buttons` key, or additional `style` / `className` settings.<div>`({ node: object, path: number[] or string[], treeIndex: number, lowerSiblingCounts: number[], isSearchMatch: bool, isSearchFocus: bool }): object`</div>
5858
getNodeKey | func | defaultGetNodeKey | | Determine the unique key used to identify each node and generate the `path` array passed in callbacks. By default, returns the index in the tree (omitting hidden nodes).<div>`({ node: object, treeIndex: number }): string or number`</div>
59-
onMoveNode | func | | | Called after node move operation. <div>`({ treeData: object[], node: object }): void`</div>
59+
onMoveNode | func | | | Called after node move operation. <div>`({ treeData: object[], node: object, treeIndex: number, path: number[] or string[] }): void`</div>
6060
onVisibilityToggle | func | | | Called after children nodes collapsed or expanded. <div>`({ treeData: object[], node: object, expanded: bool }): void`</div>
6161
reactVirtualizedListProps | object | | | Custom properties to hand to the [react-virtualized list](https://github.com/bvaughn/react-virtualized/blob/master/docs/List.md#prop-types)
6262
rowHeight | number or func | `62` | | Used by react-virtualized. Either a fixed row height (number) or a function that returns the height of a row given its index: `({ index: number }): number`

src/examples/basicExample/app.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ class App extends Component {
269269
<SortableTree
270270
treeData={treeData}
271271
onChange={this.updateTreeData}
272+
onMoveNode={({ node, treeIndex, path }) =>
273+
console.debug( // eslint-disable-line no-console
274+
'node:', node,
275+
'treeIndex:', treeIndex,
276+
'path:', path,
277+
)
278+
}
272279
maxDepth={maxDepth}
273280
searchQuery={searchString}
274281
searchFocusOffset={searchFocusIndex}

src/react-sortable-tree.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,23 @@ class ReactSortableTree extends Component {
9494
}
9595

9696
moveNode({ node, depth, minimumTreeIndex }) {
97-
const treeData = insertNode({
97+
const {
98+
treeData,
99+
treeIndex,
100+
path,
101+
} = insertNode({
98102
treeData: this.state.draggingTreeData,
99103
newNode: node,
100104
depth,
101105
minimumTreeIndex,
102106
expandParent: true,
103-
}).treeData;
107+
getNodeKey: this.props.getNodeKey,
108+
});
104109

105110
this.props.onChange(treeData);
106111

107112
if (this.props.onMoveNode) {
108-
this.props.onMoveNode({ treeData, node });
113+
this.props.onMoveNode({ treeData, node, treeIndex, path });
109114
}
110115
}
111116

0 commit comments

Comments
 (0)