To ensure you always stay at the bottom while scrolling, consider implementing the following solution:
const adjustInputHeight = (e) => {
const
input = e.target,
container = input.closest(".container"),
scrollElement = container.querySelector(".scroll");
input.style.height = "auto";
input.style.height = input.scrollHeight + "px";
// Refer to: https://stackoverflow.com/a/33193694/1762224
scrollElement.scrollTop = scrollElement.scrollHeight - scrollElement.clientHeight;
};
document.querySelectorAll("textarea").forEach((textArea) => {
Object.assign(textArea.style, {
height: `${textArea.scrollHeight}px`,
overflowY: "hidden"
});
textArea.addEventListener("input", adjustInputHeight);
});