- ) {
const { expanded } = this.state;
// This file is visible, so we highlight it.
if (expanded.has(this.props.getPath(highlightItems[0]))) {
this.focusItem(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.focusItem(highlightItems[index]);
}
}
}
focusItem = (item: Item) => {
if (!this.props.disabledFocus && this.state.focusedItem !== item) {
this.setState({ focusedItem: item });
if (this.props.onFocus) {
this.props.onFocus(item);
}
}
};
render() {
const { expanded, focusedItem } = this.state;
return (
expanded.has(this.props.getPath(item))}
focused={focusedItem}
getKey={this.props.getPath}
onExpand={item => this.setExpanded(item, true, false)}
onCollapse={item => this.setExpanded(item, false, false)}
onFocus={this.focusItem}
renderItem={(...args) =>
this.props.renderItem(...args, {
setExpanded: this.setExpanded
})
}
/>
);
}
}
export default ManagedTree;