在MUI中自动选择



**

在mui中,如何在自动完成中调用API onfocus?是什么财产帮助我实现了这一点?我使用了selectOnFocus属性,但没有达到要求

**

<Autocomplete
id="entry-description"
freeSolo
selectOnFocus
handleHomeEndKeys
disableClearable
onChange={handleSelection}
options={recentTimeTrackEntries}
inputValue={description}
getOptionLabel={(option: any) => {
return option.description;
}}
renderOption={(props, option) => {
const optionLabel =
`${option.description ? option.description : ''}${
option.projectName
? (option.description ? ', ' : '') + option.projectName
: ''
}${
option.tags.length
? option.tags.map((tag: FilteredTag) => tag.name).join(' ')
: ''
}` || '-';
return (
<li
{...props}
key={option.id}
data-entry={JSON.stringify(option)}
value={option.id}
>
{optionLabel}
</li>
);
}}
renderInput={(params) => (
<Stack direction="row" spacing={0.4}>
<TextField onChange={handleChange} {...params} />
{required ? <Typography variant="h4">*</Typography> : null}
</Stack>
)}
/>

您必须使用onOpen道具。就是一个例子

https://mui.com/material-ui/react-autocomplete/#load-打开

https://codesandbox.io/s/j8jnpe?file=/demo.tsx

请检查一下。

最新更新