componentDidUpdate()

in src/menu/stateful-container.tsx [121:155]


  componentDidUpdate(prevProps: StatefulContainerProps, prevState: StatefulContainerState) {
    if (__BROWSER__) {
      if (!prevState.isFocused && this.state.isFocused) {
        if (this.keyboardControlNode)
          this.keyboardControlNode.addEventListener('keydown', this.onKeyDown);
      } else if (prevState.isFocused && !this.state.isFocused) {
        if (this.keyboardControlNode)
          this.keyboardControlNode.removeEventListener('keydown', this.onKeyDown);
      }
    }
    var range = this.getItems().length;
    if (this.props.forceHighlight && this.state.highlightedIndex === -1 && range > 0) {
      this.internalSetState(STATE_CHANGE_TYPES.enter, {
        highlightedIndex: 0,
      });
    }
    if (range === 0 && this.state.highlightedIndex !== -1) {
      this.internalSetState(STATE_CHANGE_TYPES.enter, {
        highlightedIndex: -1,
      });
    } else if (this.state.highlightedIndex >= range) {
      this.internalSetState(STATE_CHANGE_TYPES.enter, {
        highlightedIndex: 0,
      });
    }

    if (
      this.props.isNestedMenuVisible &&
      this.props.nestedMenuHoverIndex !== prevProps.nestedMenuHoverIndex &&
      !this.props.isNestedMenuVisible(this.rootRef) &&
      !this.props.forceHighlight
    ) {
      this.setState({ highlightedIndex: -1 });
    }
  }