Bug 1535063 - add shown property to VirtualizedTree component that defines a tree item to be rendered and shown within the tree. r=nchevobbe

Differential Revision: https://phabricator.services.mozilla.com/D23358
This commit is contained in:
Yura Zenevich
2019-03-18 07:48:30 +00:00
parent 6c0a07222d
commit d65fd81594
3 changed files with 165 additions and 0 deletions

View File

@@ -205,6 +205,9 @@ class Tree extends Component {
// Handle when item is activated with a keyboard (using Space or Enter)
onActivate: PropTypes.func,
// The currently shown item, if any such item exists.
shown: PropTypes.any,
// Indicates if pressing ArrowRight key should only expand expandable node
// or if the selection should also move to the next node.
preventNavigationOnArrowRight: PropTypes.bool,
@@ -277,6 +280,7 @@ class Tree extends Component {
window.addEventListener("resize", this._onResize);
this._autoExpand();
this._updateHeight();
this._scrollItemIntoView();
}
componentWillReceiveProps(nextProps) {
@@ -293,10 +297,23 @@ class Tree extends Component {
mouseDown === nextState.mouseDown;
}
componentDidUpdate() {
this._scrollItemIntoView();
}
componentWillUnmount() {
window.removeEventListener("resize", this._onResize);
}
_scrollItemIntoView() {
const { shown } = this.props;
if (!shown) {
return;
}
this._scrollIntoView(shown);
}
_autoExpand() {
if (!this.props.autoExpandDepth) {
return;