【发布时间】:2021-08-11 02:41:56
【问题描述】:
我有一个搜索栏,它使用材料 ui 中的自动完成功能来提供建议,在其中我有一个文本字段,我将文本作为输入。
唯一的问题是,当我在 TextField 中键入任何内容时,我可以看到 2 个清除按钮(x 按钮),一个在加载屏幕的左侧,一个在右侧,当加载屏幕消失时,我得到 2 个清除按钮紧挨着。我想删除左边的那个,因为它看起来很糟糕,我不知道它为什么在那里。
Search.jsx:
<div className={searchClasses.search}>
<Autocomplete
options={isEmpty ? [] : suggestionsList}
freeSolo
style={{width: "100%"}}
getOptionLabel={(option) => option.title}
renderInput={(params) => (
<TextField
{...params}
variant="outlined"
margin="normal"
required
fullWidth
autoFocus
loading={loading}
style={{margin: 0}}
classes={{ notchedOutline: classes.input }}
onChange={handleOnChange}
onKeyDown={e => handleKeyDown(e)}
placeholder="Search..."
type="search"
InputProps={{
...params.InputProps,
startAdornment: (
<InputAdornment position="start">
<SearchIcon />
</InputAdornment>
),
endAdornment: (
<React.Fragment>
{loading ? <CircularProgress color="inherit" size={20} /> : null}
{params.InputProps.endAdornment}
</React.Fragment>
),
classes: { notchedOutline: classes.noBorder }
}}
/>
)}
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>
);
}}
/>
</div>
【问题讨论】:
标签: reactjs autocomplete material-ui next.js dropdown