Unable to give focus to Form.Input
See original GitHub issueHi,
I’m trying to give focus to an <Form.Input>
but I get an error : TypeError: this.searchField.current.focus is not a function
.
Replacing by a standard <input>
make it work.
How can I focus an input ?
Here is a sample code :
import React, {Component} from 'react';
import {Form} from 'react-bulma-components';
class Home extends Component {
constructor(props) {
super(props);
this.searchField = React.createRef();
this.focusSearchField = this.focusSearchField.bind(this);
}
render() {
return <div>
<Form.Control style={{ marginBottom: 20 }}>
<Form.Input
className="input"
type="text"
ref={this.searchField}
onChange={e => this.changeFilter(e.target.value)} />
</Form.Control>
<Button onClick={this.focusSearchField}>Focus</Button>
</div>
}
focusSearchField() {
this.searchField.current.focus();
}
}
export default Home;
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Cannot focus (click into) html input elements - Stack Overflow
The reason is that the .half divs that contain the inputs are floating. Easy fix would be to add style clear:both on you...
Read more >Cant Focus Input Field - Material Design for Bootstrap
I have the same problem when I form is loaded I want to focus in an input field but the jQuery focus function...
Read more >Bring Focus to the First Form Field with an Error
Resetting the field will involve removing the aria-invalid attribute and doing one of two things with the error message: either remove it from ......
Read more >Need help with Failed to set input focus on web page text box.
I have used the web recording function and manually capturing the UI Elements to set focus on a text box, but to no...
Read more >Unable to programmatically set focus on form input #3270
Hello I need to set a text input field to get focus when I click on an element which contains it. ... I...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
domRef or ref won’t work with useRef()?
That works ! Thanks 😃