I need autosize (elastic) for <textarea>. I need to use <textarea>, cannot use <ion-textarea> for other issues.
I was following: How to autoresize the ion-input field vertically while i am typing & https://stackblitz.com/edit/expandable-input
<ion-textarea> is working:
@Directive({ selector: 'ion-textarea[autosize]' })
But, Not for <textarea>
@Directive({ selector: 'textarea[autosize]' })
Here is My Stackblitz (autosize not working): https://stackblitz.com/edit/expandable-input-htjncw
Console error: "ERROR TypeError: Cannot read property 'style' of undefined ..."
Code:
adjust():void {
const textArea = this.element.nativeElement.getElementsByTagName('textarea')[0];
textArea.style.overflow = 'hidden';
textArea.style.height = 'auto';
textArea.style.height = textArea.scrollHeight + 'px';
}