JSFiddle - React, Tailwind, and code Playground
HTML
<textarea placeholder="|Enter Your Text"></textarea>
CSS
textarea{
width:300px;
height:100px;
color:gray;
}
JavaScript
// this example needs to be improved if you want to use in production, but I think this is a way to achieve it
$('textarea').on('keypress', function(e){
// store the placeholder
var ph = $(this).attr('placeholder');
// store the current value
var current_value = $(this).val();
// delete the placeholder from the current value (if exists)
$(this).val(function(){ return arguments[1].replace(ph, ''); });
// when pressing enter
if( e.keyCode === 13 ) {
// if there are line breaks, remove any existing placeholder and append the new one
if( /\n/g.test(current_value) ) $(this).val(current_value.replace(ph, '') + ph);
// otherwise just append the value with the placeholder
else $(this).val(current_value + ph);
// now move the cursor to the last position less the placeholder length
var mv = $(this).val().length - ph.length;
$(this)[0].setSelectionRange(mv, mv);
}
});