首页 > 解决方案 > 无法在 aoutoComplete 材质 UI 中读取 null 的属性“selectionEnd”

问题描述

我对自动完成有问题,反应文本掩码是这样的:

<MaskedInput
  {...other}
  ref={ref => {
    inputRef(ref ? ref.inputElement : null);
    return ref;
  }}
  mask={[
    /\d/,
    /\d/,
    /\d/,
    /\d/,
    ' ',
    /\d/,
    /\d/,
    /\d/,
    ' ',
    /\d/,
    /\d/,
    /\d/,
    /\d/,
  ]}
  placeholderChar={'\u2000'}
/>;

自动完成组件是这样的:

<AmountAutoComplete
  options={this.state.autoCompleteOptions.map(option => option.title)}
  renderInput={params => {
    return (
      <TextField
        value={this.props.value}
        onChange={e => {
          onValueChange(e.currentTarget.value, '');
        }}
        InputProps={{
          inputComponent: this.TextMaskCustom,
        }}
      />
    );
  }}
/>;

错误是

无法在 handleClick 处读取 null 的属性“selectionEnd”(useAutocomplete.js:763)

并且在 useAutocomplete.js:763 中有关于 inputRef 的错误:

var handleClick = function handleClick() { if (firstFocus.current && inputRef.current.selectionEnd - inputRef.current.selectionStart === 0) { inputRef.current.focus(); inputRef.current.select(); }

标签: reactjsautocompletematerial-ui

解决方案


我应该像这样将参数发送到 textField :

<TextField
    {...params}
     InputProps={{
     ...params.InputProps,
    }} 
 />

推荐阅读