JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text" id="myInput" value="Default value" ></input>
<input id="txt" type="text" onkeypress="this.style.width = ((this.value.length + 1) * 8) + 'px';">

JavaScript

var input = document.getElementById ("myInput");           
input.style.width = (input.value.length * 7) + "px";