Skip to content

Commit

Permalink
[tree] escape key dismisses any info modal
Browse files Browse the repository at this point in the history
This implements what we think is an intuitive UI, and also helps with
the bug described in #1243 where removing/disabling a strain-filter
results in the tree visualisation falling out-of-sync with the modal.

See #1479 for context.

Closes #1479
  • Loading branch information
jameshadfield committed Mar 16, 2022
1 parent 011c19d commit ed4bf13
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/components/tree/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class Tree extends React.Component {
root: [0, 0]
}));
};
/* pressing the escape key should dismiss an info modal (if one exists) */
this.handlekeydownEvent = (event) => {
if (event.keyCode===27 && this.state.selectedNode) { // key 27 is esc
this.clearSelectedNode(this.state.selectedNode);
}
};
}
setUpAndRenderTreeToo(props, newState) {
/* this.setState(newState) will be run sometime after this returns */
Expand All @@ -52,6 +58,7 @@ class Tree extends React.Component {
renderTree(this, false, newState.treeToo, props);
}
componentDidMount() {
document.addEventListener('keyup', this.handlekeydownEvent);
if (this.props.tree.loaded) {
const newState = {};
newState.tree = new PhyloTree(this.props.tree.nodes, "LEFT", this.props.tree.idxOfInViewRootNode);
Expand Down Expand Up @@ -96,6 +103,10 @@ class Tree extends React.Component {
if (Object.keys(newState).length) this.setState(newState);
}

componentWillUnmount() {
document.removeEventListener('keyup', this.handlekeydownEvent);
}

getStyles = () => {
const activeResetTreeButton = this.props.tree.idxOfInViewRootNode !== 0 ||
this.props.treeToo.idxOfInViewRootNode !== 0;
Expand Down

0 comments on commit ed4bf13

Please sign in to comment.