fix: text area height calculation in chats

isekai-main
Barış Soner Uşaklı 2 years ago
parent 9e416d7fda
commit c52916de8e

@ -200,7 +200,7 @@ define('forum/chats', [
textarea.on('input', function () {
const isAtBottom = messages.isAtBottom(parent.find('.chat-content'));
textarea.css({ height: 0 });
textarea.css({ height: textarea.prop('scrollHeight') + 'px' });
textarea.css({ height: messages.calcAutoTextAreaHeight(textarea) + 'px' });
if (isAtBottom) {
messages.scrollToBottom(parent.find('.chat-content'));
}

@ -54,16 +54,21 @@ define('forum/chats/messages', [
messages.updateTextAreaHeight = function (chatContentEl) {
const textarea = chatContentEl.find('[component="chat/input"]');
textarea.css({ height: messages.calcAutoTextAreaHeight(textarea) + 'px' });
};
messages.calcAutoTextAreaHeight = function (textarea) {
const scrollHeight = textarea.prop('scrollHeight');
textarea.css({ height: scrollHeight + 'px' });
const borderTopWidth = parseFloat(textarea.css('border-top-width'), 10) || 0;
const borderBottomWidth = parseFloat(textarea.css('border-bottom-width'), 10) || 0;
return scrollHeight + borderTopWidth + borderBottomWidth;
};
function autoresizeTextArea(textarea) {
const scrollHeight = textarea.prop('scrollHeight');
textarea.css({ height: scrollHeight + 'px' });
textarea.css({ height: messages.calcAutoTextAreaHeight(textarea) + 'px' });
textarea.on('input', function () {
textarea.css({ height: 0 });
textarea.css({ height: textarea.prop('scrollHeight') + 'px' });
textarea.css({ height: messages.calcAutoTextAreaHeight(textarea) + 'px' });
});
}

Loading…
Cancel
Save