It would not fit the requirements respectively listening only to the enter key would not produce a proper behavior. New lines are also triggered when length of the text reach the width of the textarea. As these lines, I didn’t typed any enter key and the text is displayed on multiples lines, therefore if it was a textarea, this area should had been resized
I’ve found another solution how to handle the resizeing of a textarea, maybe it can help someone. I’ve wrote this, because I need it just once and and not multiple times across the app. If You need the resizeing across Your app, You could store the adjustTextarea(event) a helper class / provider or something like that.
/**
* function to adjust the height of the message textarea
* @param {any} event - the event, which is provided by the textarea input
* @return {void}
*/
protected adjustTextarea(event: any): void {
let textarea: any = event.target;
textarea.style.overflow = 'hidden';
textarea.style.height = 'auto';
textarea.style.height = textarea.scrollHeight + 'px';
return;
}
Cool but your solution do nothing if attribut “readonly” is set to "true"
work only if text area value change, not if the value is setting programmaticaly
I think you’re better of using the “rows” attribute of the textarea element in combination with counting the amount of lines in your textarea. See my example:
adjustTextarea(event: any): void {
let textarea: any = event.target;
textarea.rows = textarea.value.split('\n').length;
return;
}
Should be the most reliable way of automatically adjusting your textarea.
Can you be a bit more specific on how you fixed this problem with copy/paste of text?
Consistently seeing this issue on iPhone X. You can paste about 2 paragraphs of text but on the 3rd you cannot get to the last line of the input, it is hidden under the keyboard.