Skip to content

Instantly share code, notes, and snippets.

@piyonishi
Last active February 2, 2025 20:59
Show Gist options
  • Save piyonishi/409ecbd07f7b86b7da205ad61210a275 to your computer and use it in GitHub Desktop.
Save piyonishi/409ecbd07f7b86b7da205ad61210a275 to your computer and use it in GitHub Desktop.
How to put focus at the end of an input with React.js
// https://coderwall.com/p/0iz_zq/how-to-put-focus-at-the-end-of-an-input-with-react-js
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>
}
@tomasz-konecki
Copy link

Thank you very much! It saved me a lot of headache. :)

@evilPaprika
Copy link

Just what I needed, many thanks ๐Ÿ˜˜

@bgrubb83
Copy link

bgrubb83 commented Feb 2, 2025

Big help, thanks ๐Ÿ‘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment