as per material ui previous version 4 or current version 5, You can simply focus autocomplete input element using autoFocus props, if autoFocus is set to true then input element will be focused on each first mount of autocomplete component.
const [query, setQuery] = useState('');
<Autocomplete
.....
renderInput={(params) => {
const { InputLabelProps, InputProps, ...rest } = params;
return <InputBase
{...params.InputProps}
{...rest}
name="query"
value={query}
onChange={handleSearch}
autoFocus
/>
}}
/>
// it is just an example , you can handle below function as per your wish
function handleOnSearch({ currentTarget = {} }) {
const { value } = currentTarget;
setQuery(value);
}
If you want to open an autocomplete input once a button is clicked :-
//button to be clicked to open autocomplete input
const clickButton=()=>{
setOpen(true)
}
const handleClose =()=>{
setOpen(false)
}
<Dialogue
close={handleClose}
open={open}
>
<DialogActions>
<Autocomplete
.....
renderInput={(params) => {
const { InputLabelProps, InputProps, ...rest } = params;
return <InputBase
{...params.InputProps}
{...rest}
name="query"
value={query}
onChange={handleSearch}
autoFocus
/>
}}
/>
</DialogActions>
</Dialogue>
Cheers!!!