Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Commit

Permalink
Prevent _scrollNodeIntoView click on Tree node click.
Browse files Browse the repository at this point in the history
The scrollNodeIntoView function is called from the _focus function,
which can be called either when the user navigate via the keyboard,
or when a user click a node.
When navigating with the keyboard, it makes sense because we might
focus a node which isn't visible on the viewport so we need to scroll
it into view.
When clicking a node, obviously it is already visible (unless we call
node element.click , but that's never done in the code). Because it's
already visible, no need to check if we should scroll, so we save
the computation time.
  • Loading branch information
nchevobbe committed Apr 20, 2018
1 parent bc9bd6f commit 7368f1a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/devtools-components/src/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,11 @@ class Tree extends Component {
* top or the bottom of the scrollable container when the element is
* off canvas.
*/
_focus(item, options) {
this._scrollNodeIntoView(item, options);
_focus(item, options = {}) {
const { preventAutoScroll } = options;
if (item && !preventAutoScroll) {
this._scrollNodeIntoView(item, options);
}
if (this.props.onFocus) {
this.props.onFocus(item);
}
Expand Down Expand Up @@ -772,7 +775,9 @@ class Tree extends Component {
onExpand: this._onExpand,
onCollapse: this._onCollapse,
onClick: (e) => {
this._focus(item);
// Since the user just clicked the node, there's no need to check if it should
// be scrolled into view.
this._focus(item, {preventAutoScroll: true});
if (this.props.isExpanded(item)) {
this.props.onCollapse(item);
} else {
Expand Down

0 comments on commit 7368f1a

Please sign in to comment.