Sal*_*niy 7 javascript jsx reactjs material-ui
<Autocomplete
freeSolo
size="small"
id="filter-locks-autocomplete"
options={json_list ? json_list : []}
groupBy={(option) => option.lock.building}
getOptionLabel={(option) => (option.name)}
inputValue={inputValue}
onInputChange={(event, newInputValue) => setInputValue(newInputValue)}
renderInput={(params) => (
<TextField
{...params}
variant="standard"
label={'lock'}
InputProps={{
startAdornment: (
<InputAdornment position="start">
<Search sx={{ color: "black", fontSize: 20, marginLeft: "2px" }} />
{params.InputProps.startAdornment}
</InputAdornment>
),
}}
/>
)}
/>;
Run Code Online (Sandbox Code Playgroud)
但是,在框内单击时,选项列表不再出现。如果我像这样删除 InputProps <TextField />:
<Autocomplete
freeSolo
size="small"
id="filter-locks-autocomplete"
options={json_list ? json_list : []}
groupBy={(option) => option.lock.building}
getOptionLabel={(option) => option.name}
inputValue={inputValue}
onInputChange={(event, newInputValue) => setInputValue(newInputValue)}
ListboxProps={{ sx: { zIndex: 1500 } }}
renderInput={(params) => (
<TextField {...params} variant="standard" label={"lock name"} />
)}
/>;
Run Code Online (Sandbox Code Playgroud)
选项列表按预期显示。
有没有办法可以将 inputAdornment (只是一个搜索图标)添加到 AutoComplete 组件而不删除选项列表?
sod*_*kit 10
我在这里找到了解决方案,您可以尝试以下代码
<Autocomplete
id="tags-standard"
options={top100Films}
getOptionLabel={option => option.title}
defaultValue={[top100Films[13]]}
renderInput={params => {
return (
<TextField
{...params}
variant="standard"
label="Multiple values"
placeholder="Favorites"
fullWidth
InputProps={{
...params.InputProps,
startAdornment: (
<>
<InputAdornment position="start">
<SearchIcon />
</InputAdornment>
{params.InputProps.startAdornment}
</>
)
}}
/>
);
}}
/>
Run Code Online (Sandbox Code Playgroud)
它运行良好。您还可以在CodeSandbox中查看
有关更多详细信息,请查看此Github Material-ui 问题
| 归档时间: |
|
| 查看次数: |
2561 次 |
| 最近记录: |