Explanation: I am facing an issue in Angular 2 regarding the chat screen. I need the chat screen to dynamically increase in size as I type, up to a maximum of 5 lines, and then show a scrollbar. How can I achieve this functionality?
Problem: The current behavior is not as expected. The scrollbar needs to be limited to 5 lines and the contract/expand feature is not working properly.
Requirement: The chat screen should expand as I type and contract when I press backspace. Once it reaches 5 lines, a scrollbar should appear.
My code:
home.ts
autogrow(){
let textArea = document.getElementById("textarea")
textArea.style.overflow = 'hidden';
textArea.style.height = '0px';
textArea.style.height = textArea.scrollHeight + 'px';
}
home.html
<textarea id="textarea" (keyup)="autogrow()" ></textarea>