You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
916 B
JavaScript

function adjustTextHeight(textarea) {
// MAKE THE TEXTAREA'S HEIGHT ADJUSTABLE
if (textarea.value.trim() === '') {
textarea.style.height = '50px';
} else {
textarea.style.height = textarea.scrollHeight + 'px';
}
// DISPLAY AND HIDE THE SUBMIT BUTTON
const submitButton = document.querySelector('#sendMessage button[type="submit"]');
if (textarea.value.trim() === '') {
submitButton.classList.add('hidden');
} else {
submitButton.classList.remove('hidden');
}
}
const form = document.querySelector('#sendMessage');
const textarea = document.querySelector('#dynamicTextarea');
const conversationContainer = document.getElementById('conversation');
form.addEventListener('submit', (event) => {
textarea.style.height = '50px';
setTimeout(() => {
conversationContainer.scrollTop = conversationContainer.scrollHeight;
}, 100);
});