Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,14 @@ _node_.**childIndex**

Returns the node's index in relation to its siblings.

_node_.**path**

Returns an array that represents the ancestry of the node, starting from the root node and ending with the current node. Each element in the array corresponds to an ID in the node's hierarchy.

_node_.**key**

Returns the unique React key associated with the node.

_node_.**next**

Returns the next visible node. The node directly under this node in the tree component. Returns null if none exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export function DefaultContainer() {
width={tree.width}
itemSize={tree.rowHeight}
overscanCount={tree.overscanCount}
itemKey={(index) => tree.visibleNodes[index]?.id || index}
itemKey={(index) => tree.visibleNodes[index]?.key || index}
outerElementType={ListOuterElement}
innerElementType={ListInnerElement}
onScroll={tree.props.onScroll}
Expand Down
20 changes: 20 additions & 0 deletions packages/react-arborist/src/interfaces/node-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ export class NodeApi<T = any> {
}
}

get path() {
const path = [this.id];
let parent = this.parent;

while (parent) {
path.push(parent.id);
parent = parent.parent;
}

return path.reverse();
}

get key() {
if (this.id) {
return this.path.join(',');
}

return null;
}

get next(): NodeApi<T> | null {
if (this.rowIndex === null) return null;
return this.tree.at(this.rowIndex + 1);
Expand Down