[英]Multiline options for Material UI autocomplete
I'm trying to make an autocomplete where each option has firstName
and lastName
of a user
on the first line and their id
on the second.我正在尝试进行自动完成,其中每个选项在第一行都有
user
的firstName
和lastName
,在第二行有他们的id
。
Here is what I've tried这是我尝试过的
<Autocomplete
freeSolo
disableClearable
options={users}
getOptionLabel={(option) => option.firstName + " " + option.lastName}
renderOption={(option) => {
return (
<>
<div>
{option.firstName} {option.lastName}
</div>
<div>{option.id}</div>
</>
);
}}
renderInput={(params) => (
<TextField
{...params}
label="Username or ID"
// margin="normal"
variant="outlined"
value={name}
onChange={handleChange}
className={classes.input}
InputProps={{
...params.InputProps,
type: "search",
}}
/>
)}
/>
I'm returning a component from renderOption
but it does not pay attending to <div>
or <br/>
tags.我正在从
renderOption
返回一个组件,但它不需要关注<div>
或<br/>
标签。 It simply puts everything next to each other它只是将所有东西放在一起
Just use proper div to display on next line.只需使用适当的 div 在下一行显示。 Single Outer div and one nested div to show the id on next line.
单个外部 div 和一个嵌套 div 以在下一行显示 id。
renderOption={(option) => {
return (
<>
<div>
{option.title} {option.title}
<div>
{option.title}
</div>
</div>
</>
);
}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.