我正在使用Material UI自动完成:
import TextField from "@material-ui/core/TextField";
import Autocomplete from "@material-ui/lab/Autocomplete";
import parse from "autosuggest-highlight/parse";
import match from "autosuggest-highlight/match";
<Autocomplete
id="cityAutocomplete"
options={cities}
// onChange={(event, value) => console.log(value)} // prints the selected value
onChange={(event, value) => callback(value)}
getOptionLabel={option => option.title}
renderInput={params => (
<TextField
{...params}
variant="outlined"
fullWidth
type='text'
autoComplete="off"
placeholder="Enter City"
/>
)}
renderOption={(option, { inputValue }) => {
const matches = match(option.title, inputValue);
const parts = parse(option.title, matches);
return (
<div>
{parts.map((part, index) => (
<span
key={index}
style={{ fontWeight: part.highlight ? 700 : 400 }}
>
{part.text}
</span>
))}
</div>
);
}}
/>
当用户开始输入TextField
时,总是会提示已提交的先前值。
如何防止TextField
显示自动填充?
我添加了autoComplete="off"
,但仍在发生。