Material 自动完成不适用于 InputProps
Material Autocomplete does not work with InputProps
我正在尝试更改通过 Autocomplete
呈现的 TextField
的边框,但是当我添加 InputProps
道具时,Autocomplete
不再呈现 Chip
s
<Autocomplete
multiple
freeSolo
options={options}
renderTags={(value, { className, onDelete }) =>
value.map((option, index) => (
<Chip
key={index}
variant="outlined"
data-tag-index={index}
tabIndex={-1}
label={option}
className={className}
color="secondary"
onDelete={onDelete}
/>
))
}
renderInput={(params) => (
<TextField
{...params}
id={id}
className={textFieldStyles.searchField}
label={label}
value={value}
onChange={onChange}
variant="outlined"
//InputProps={{
// classes: {
// input: textFieldStyles.input,
// notchedOutline: textFieldStyles.notchedOutline
// }
//}}
InputLabelProps={{
classes: {
root: textFieldStyles.label
}
}}
/>
)}
/>
The above code works, and once I uncomment the InputProps
line, the input no longer renders Chip
s when an item is selected or entered.
谢谢
发生这种情况是因为 InputProps 属性覆盖了 params 的 InputProps 参数,您必须合并 params 的 InputProps 属性:
InputProps={{
...params.InputProps,
classes: {
input: textFieldStyles.input,
notchedOutline: textFieldStyles.notchedOutline
}
}}
我正在尝试更改通过 Autocomplete
呈现的 TextField
的边框,但是当我添加 InputProps
道具时,Autocomplete
不再呈现 Chip
s
<Autocomplete
multiple
freeSolo
options={options}
renderTags={(value, { className, onDelete }) =>
value.map((option, index) => (
<Chip
key={index}
variant="outlined"
data-tag-index={index}
tabIndex={-1}
label={option}
className={className}
color="secondary"
onDelete={onDelete}
/>
))
}
renderInput={(params) => (
<TextField
{...params}
id={id}
className={textFieldStyles.searchField}
label={label}
value={value}
onChange={onChange}
variant="outlined"
//InputProps={{
// classes: {
// input: textFieldStyles.input,
// notchedOutline: textFieldStyles.notchedOutline
// }
//}}
InputLabelProps={{
classes: {
root: textFieldStyles.label
}
}}
/>
)}
/>
The above code works, and once I uncomment the InputProps
line, the input no longer renders Chip
s when an item is selected or entered.
谢谢
发生这种情况是因为 InputProps 属性覆盖了 params 的 InputProps 参数,您必须合并 params 的 InputProps 属性:
InputProps={{
...params.InputProps,
classes: {
input: textFieldStyles.input,
notchedOutline: textFieldStyles.notchedOutline
}
}}