Skip to content

Commit

Permalink
Use shouldComponentUpdate to avoid unnecessary calls to updateFocus i…
Browse files Browse the repository at this point in the history
…n EuiContextMenuPanel. (elastic#3)
  • Loading branch information
cjcenizal authored and uboness committed Jan 27, 2018
1 parent aa0a6e8 commit 9f09e2c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/components/context_menu/context_menu_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,25 @@ export class EuiContextMenuPanel extends Component {
}
}

shouldComponentUpdate(nextProps, nextState) {
// Prevent calling `this.updateFocus()` below if we don't have to.
if (nextProps.hasFocus !== this.props.hasFocus) {
return true;
}

if (nextState.isTransitioning !== this.state.isTransitioning) {
return true;
}

if (nextState.focusedItemIndex !== this.state.focusedItemIndex) {
return true;
}

return false;
}

componentDidUpdate() {
// this.updateFocus();
this.updateFocus();
}

menuItemRef = (index, node) => {
Expand Down

0 comments on commit 9f09e2c

Please sign in to comment.