- ) {
const { expanded } = this.state;
// This file is visible, so we highlight it.
if (expanded.has(this.props.getPath(highlightItems[0]))) {
this.props.onFocus(highlightItems[0]);
} else {
// Look at folders starting from the top-level until finds a
// closed folder and highlights this folder
const index = highlightItems
.reverse()
.findIndex(
item =>
!expanded.has(this.props.getPath(item)) && item.name !== "root"
);
if (highlightItems[index]) {
this.props.onFocus(highlightItems[index]);
}
}
}
render() {
const { expanded } = this.state;
return (
expanded.has(this.props.getPath(item))}
focused={this.props.focused}
getKey={this.props.getPath}
onExpand={(item, shouldIncludeChildren) =>
this.setExpanded(item, true, shouldIncludeChildren)
}
onCollapse={(item, shouldIncludeChildren) =>
this.setExpanded(item, false, shouldIncludeChildren)
}
onFocus={this.props.onFocus}
renderItem={(...args) =>
this.props.renderItem(...args, {
setExpanded: this.setExpanded,
})
}
/>
);
}
}
export default ManagedTree;