Last Updated: September 27, 2021
·
24.66K
· MichalHantl

How to put focus at the end of an input with React.js

Pretty easy to do, but couldn't find it in 1 minute so posting here :)

moveCaretAtEnd(e) {
  var temp_value = e.target.value
  e.target.value = ''
  e.target.value = temp_value
}


render() {
  <textarea 
    value={value}
    autoFocus
    onFocus={this.moveCaretAtEnd}
  ></textarea>
}