ElemeFE / element-react

Element UI
https://elemefe.github.io/element-react/index
MIT License
2.83k stars 443 forks source link

After searching in select, it triggers when the keyboard is up/down, and the page crashes. errMsg:Uncaught Invariant Violation: Maximum update depth exceeded. #980

Open super-d2 opened 5 years ago

super-d2 commented 5 years ago

Description

After searching in select, it triggers when the keyboard is up/down, and the page crashes. Errors were reported as follows: Uncaught Invariant Violation: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

Reproduce Steps

After searching in select, it triggers when the keyboard is up/down, and the page crashes.

Error Trace (if possible)

Uncaught Invariant Violation: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

Solution

value: function navigateOptions(direction) { ... ... ... if (options.length != options.filter(function (item) { return item.props.disabled === true; }).length) { if (direction === 'next') { hoverIndex++;

      while ( hoverIndex < options.length && options[hoverIndex].props.disabled === true || options[hoverIndex].props.groupDisabled === true || !options[hoverIndex].state.visible) {
        hoverIndex++;
      }

       if (hoverIndex === options.length) {
        hoverIndex = 0;
      }
    }

    if (direction === 'prev') {
      hoverIndex--;

      while ( hoverIndex > 0 && options[hoverIndex].props.disabled === true || options[hoverIndex].props.groupDisabled === true || !options[hoverIndex].state.visible) {
        hoverIndex--;
      }

      if (hoverIndex < 0) {
        hoverIndex = options.length - 1;
      }
    }
  }

  ...
  ...
}

Additional Information

  1. There are still some problems with this change, such as: the upper and lower keys can only flip the visual area;

  2. I see that the props attribute does not exist.