I need to display the dropdown options of a select when I click on a button.
I tried with the ref and focus or click but it's not working.
import React from "react";
import ReactDOM from "react-dom";
import "./styles.css";
function App() {
const [value, setValue] = React.useState(false);
const selectRef = React.useRef();
const handleClick = () => {
// selectRef.current.focus();
selectRef.current.click();
};
return (
<div className="App">
<button onClick={handleClick}>click me !</button>
<select
open
ref={selectRef}
value={value ? "activate" : "deactivate"}
onChange={e => setValue(e.target.value === "activate")}
>
<option value="activate">Activate</option>
<option value="deactivate">Deactivate</option>
</select>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
I need when I click on the button the select show me the dropdown options