具有自动完成文本字段的材质UI始终显示自动填充

时间:2019-11-23 10:38:04

标签: javascript reactjs material-ui textfield

我正在使用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",但仍在发生。

0 个答案:

没有答案