Line breaks (\n) in a textarea field work as expected in Chrome. However, the Safari default stylesheet overrides these line breaks.
We can mock a placeholder by adding a background image to the text area.
If there is no text in the textarea, show the background image. If the textarea is in focus, or there is a value, don't show the background image.
<TextField
onChange={onTexfieldChange}
value={textAreaValue}
id={'text-area-img-placeholder'}
style={{backgroundImage: (textAreaValue) && 'none'}}
/>
I am using styled components in React, but you can replace TextField
with HTML textarea.
The style attribute of the TextField
ensures that if there is a value in the textarea (textAreaValue), the background image is removed.
#text-area-img-placeholder {
background-image: url(./fileName.png);
background-repeat: no-repeat;
background-size: contain;
}
#text-area-img-placeholder:focus{
background-image: none;
}
Add this CSS to cover the background image over the entire textarea. When the HTML is in focus, remove the background image.