JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text" placeholder="Type something…" value='01234'>
<input type="text" placeholder="Type something…" value='012345678'>
<input type="text" placeholder="Type something…" value='012'>
<input type="text" placeholder="Type something…" value='0'>

CSS

.mini{
    width:10px;
}

JavaScript

$("input").each(function(){
    var myLength = $(this).val().length;
    if(myLength == 1){
        $(this).attr('size', myLength);
        $(this).attr('class', 'mini');
    }else{
        $(this).attr('size', myLength);    
    }
    
});