我想使用 Material ui 中的自动完成(来自 Material-Ui 库)组件来选择多个选项,并且这些选项不应该由用户(直接)删除。
我面临的问题是,如果用户聚焦组件并按退格键,就像删除文本一样,则可以从自动完成中删除选项。
这是我正在使用的组件:
<Autocomplete multiple
options={options}
getOptionLabel={option => option.title}
renderInput={params =>
<TextField {...params} label="Autocomplete" variant="outlined" />
}
onChange={this.onAutocompleteChange.bind(this)}
getOptionSelected={(option: Option, value: Option) => option.value === value.value}
filterSelectedOptions={true}
renderTags={(tagValue, getTagProps) =>
tagValue.map((option, index) => (
<Chip key={option.value} label={option.title} color="primary" />
))
}
disableClearable={true}
/>
Run Code Online (Sandbox Code Playgroud)
disable={true}没有任何效果。InputProps={{ disabled: true }}或InputProps={{ readOnly: true }}到 TextField 会完全禁用自动完成功能。ChipProps={{ disabled: true }}到自动完成功能没有任何效果。谢谢阅读!