How to add autofocus property in LI element in react? I've used through ref but is not working.
render() {
return (
<div>
<li ref={(re) => re.focus()}>aaa</li>
</div>
)
}
How to add autofocus property in LI element in react? I've used through ref but is not working.
render() {
return (
<div>
<li ref={(re) => re.focus()}>aaa</li>
</div>
)
}
Try using componentDidMount
and focusing the ref inside that function.
Also, like Tomasz said, an li
element is not focusable, so you would need to use an input, button, or anchor-type element to be able to focus.
Focus works only on controls like input, button, anchors. You can't do it on list elements, divs etc. Maybe just make it a button? Clickable elements should be buttons / anchors.