JSFiddle - React, Tailwind, and code Playground
by teemas
HTML
<!DOCTYPE html>
<html>
<body>
<p>Press a key inside the text field to set a red background color.</p>
<input type="text" id="demo" maxlength=5 onkeyup="myFunction()">
</body>
</html>
JavaScript
function myFunction() {
if (document.getElementById("demo").selectionStart === parseInt(document.getElementById("demo").getAttribute('maxlength'), 10)) {
document.getElementById("demo").setSelectionRange(0,0);
}
}