From 9f09e2c33703e6d6bae0b48a7f7bcbc22c36bbf7 Mon Sep 17 00:00:00 2001 From: CJ Cenizal Date: Fri, 26 Jan 2018 13:08:11 -0800 Subject: [PATCH] Use shouldComponentUpdate to avoid unnecessary calls to updateFocus in EuiContextMenuPanel. (#3) --- .../context_menu/context_menu_panel.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/components/context_menu/context_menu_panel.js b/src/components/context_menu/context_menu_panel.js index 6be9160b697..08a20a8b8df 100644 --- a/src/components/context_menu/context_menu_panel.js +++ b/src/components/context_menu/context_menu_panel.js @@ -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) => {