mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: text area height calculation in chats
This commit is contained in:
@@ -200,7 +200,7 @@ define('forum/chats', [
|
|||||||
textarea.on('input', function () {
|
textarea.on('input', function () {
|
||||||
const isAtBottom = messages.isAtBottom(parent.find('.chat-content'));
|
const isAtBottom = messages.isAtBottom(parent.find('.chat-content'));
|
||||||
textarea.css({ height: 0 });
|
textarea.css({ height: 0 });
|
||||||
textarea.css({ height: textarea.prop('scrollHeight') + 'px' });
|
textarea.css({ height: messages.calcAutoTextAreaHeight(textarea) + 'px' });
|
||||||
if (isAtBottom) {
|
if (isAtBottom) {
|
||||||
messages.scrollToBottom(parent.find('.chat-content'));
|
messages.scrollToBottom(parent.find('.chat-content'));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,16 +54,21 @@ define('forum/chats/messages', [
|
|||||||
|
|
||||||
messages.updateTextAreaHeight = function (chatContentEl) {
|
messages.updateTextAreaHeight = function (chatContentEl) {
|
||||||
const textarea = chatContentEl.find('[component="chat/input"]');
|
const textarea = chatContentEl.find('[component="chat/input"]');
|
||||||
|
textarea.css({ height: messages.calcAutoTextAreaHeight(textarea) + 'px' });
|
||||||
|
};
|
||||||
|
|
||||||
|
messages.calcAutoTextAreaHeight = function (textarea) {
|
||||||
const scrollHeight = textarea.prop('scrollHeight');
|
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) {
|
function autoresizeTextArea(textarea) {
|
||||||
const scrollHeight = textarea.prop('scrollHeight');
|
textarea.css({ height: messages.calcAutoTextAreaHeight(textarea) + 'px' });
|
||||||
textarea.css({ height: scrollHeight + 'px' });
|
|
||||||
textarea.on('input', function () {
|
textarea.on('input', function () {
|
||||||
textarea.css({ height: 0 });
|
textarea.css({ height: 0 });
|
||||||
textarea.css({ height: textarea.prop('scrollHeight') + 'px' });
|
textarea.css({ height: messages.calcAutoTextAreaHeight(textarea) + 'px' });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user