8

是否可以有一个下拉字段,但能够添加下拉菜单建议的值以外的值?

类似于将showAllItems 设置为 true 且没有自动完成功能的自动完成字段

编辑:

我想要实现的只是提交带有自定义值的表单或从下拉列表中选择用户(根据用户的选择)

4

2 回答 2

3

使用onNewRequest属性。根据https://github.com/callemall/material-ui/blob/master/src/auto-complete.jsx

const AutoComplete = React.createClass({

...

render() {

...

return (
  <div style={mergedRootStyles} onKeyDown={this._handleKeyDown}>
    <div style={{width: '100%',}}>
      <TextField
        {...other}
        ref="searchTextField"
        value={this.state.searchText}
        onEnterKeyDown={() => {
          setTimeout(() => {
            this._close();
          }, this.props.touchTapCloseDelay);
          this.props.onNewRequest(this.state.searchText);
        }}

...

每次用户按下时都会调用使用此属性传递的函数Enter,因此您可以在该函数内部处理提交输入。

于 2016-01-04T14:31:58.020 回答
0

使用 mui 自动完成功能,您走在了正确的轨道上。尝试使用该freeSolo选项

https://mui.com/components/autocomplete/#free-solo

于 2022-02-10T23:20:46.540 回答