JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text"></input>

CSS

p { padding:50px; }
        
input { 
    border:1px solid gray;
    padding:6px; 
    font-size:26px;
    font-family:monospace;
    outline:none; 
}

JavaScript

function checkLength() {
    var len = $("input:text").val().length;
    $("input:text").attr("size", len === 0 ? 1 : len + 1);
}

$("input:text").keydown(function() {
    setTimeout(checkLength, 1);
});