Skip to content

Instantly share code, notes, and snippets.

@piyonishi
Last active December 21, 2023 09:48
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>
}
@jhvissotto
Copy link

Nicee!!! Work for me! Thanks =)

@SebasG22
Copy link

SebasG22 commented Jun 3, 2021

Thanks, this works perfectly.
🚀

@mbliok
Copy link

mbliok commented Dec 5, 2022

Prfect. mersi

@tomasz-konecki
Copy link

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

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