I'm using Material Ui Autocomplete component. I would like that when the user types something, and he gets no results, the noOptionsText shows a button that can be clicked to do something:
import React from "react";
import TextField from "@material-ui/core/TextField";
import Autocomplete from "@material-ui/lab/Autocomplete";
import Button from "@material-ui/core/Button";
export default function App() {
return (
<Autocomplete
options={["HELLO", "HI"]}
renderInput={(params) => (
<TextField {...params} label="Combo box" variant="outlined" />
)}
noOptionsText={
<Button onClick={() => console.log("CLICK SUCCESSFUL")}>
No results! Click me
</Button>
}
/>
);
}
Here the button appears successfully, but then when I click it the Autocomplete is closed before the button can receive the click.
It works if I set debug={true} to force keep the menu open, but this have many other side effects.
Tried also forcing open={true} but it still gets closed.
How would you do that?
Codesandbox demo: https://codesandbox.io/s/vigilant-haslett-sngyb?file=/src/App.js