When you want to use AutoComplete, to enter @ in the text box, you will automatically fill in the mailbox behind it.

when registering, you need to fill in the mailbox. I hope you can see the optional mailbox under the text box after the user enters @. Can you give me some guidance?

Dec.07,2021

A demo
mailbox association completion


The second example of

ant design AutoComplete is ah

class Complete extends React.Component {
  state = {
    result: [],
  }

  handleSearch = (value) => {
    let result;
    if (!value || value.indexOf('@') >= 0) {
      result = [];
    } else {
      result = ['gmail.com', '163.com', 'qq.com'].map(domain => `${value}@${domain}`);
    }
    this.setState({ result });
  }

  render() {
    const { result } = this.state;
    const children = result.map((email) => {
      return <Option key={email}>{email}</Option>;
    });
    return (
      <AutoComplete
        style={{ width: 200 }}
        onSearch={this.handleSearch}
        placeholder="input here"
      >
        {children}
      </AutoComplete>
    );
  }
}

<body>
        <div>
            <input type="email" list="mail" id="input">
            <datalist id="mail">
                <option value="@qq.com">@qq.com</option>
                <option value="@baidu.com">@baidu.com</option>
                <option value="@360.com">@360.com</option>
                <option value="@fuckqq.com">@fuckqq.com</option>
            </datalist>
        </div>
    </body>
    <script type="text/javascript">
        $('-sharpinput').on('input',function() {
            $('option').each(function(){
                var o = $(this).val();
                var p = $('-sharpinput').val().replace(/@\S*$/,'');
                $(this).val(p+o.replace(/\S*(?=@)/,''));
                $(this).text(p+o.replace(/\S*(?=@)/,''))
            })
        })
    </script>
Menu