I´d like to help with this problem: I´ve got this example code below:
import React, { useRef, useEffect } from "react";
function App() {
const inputRef = useRef(null);
useEffect(() => {
const testElement = document.querySelectorAll(".active");
testElement.length > 0 && inputRef.current.focus();
}, []);
return (
<div style={{width: 200, height: 190, display: "flex", flexDirection: "column", justifyContent: "space-between"}}>
<input id={1} type="text" ref={inputRef} />
<input id={2} type="text" ref={inputRef} />
<input id={3} className={"active"} type="text" ref={inputRef} />
<input id={4} type="text" ref={inputRef} />
</div>
);
}
export default App;
And I like to know, how to focus on concrete element which has some class name. In my case it´s "active" class name on input field with id "3". But the problem is, that it´s not working and focused is the input element with id "4".
Thanky you.