Fix auto resizing textareas scrolling to the top on focus

This commit is contained in:
JonnyWong16 2018-07-25 18:39:40 -07:00
parent ce2982d948
commit ab92e48d2e
2 changed files with 6 additions and 0 deletions

View file

@ -766,9 +766,12 @@
// auto resizing textarea for custom notification message body // auto resizing textarea for custom notification message body
$('textarea[data-autoresize]').each(function () { $('textarea[data-autoresize]').each(function () {
var modal_body = $(this).closest('.modal-body');
var offset = this.offsetHeight - this.clientHeight; var offset = this.offsetHeight - this.clientHeight;
var resizeTextarea = function (el) { var resizeTextarea = function (el) {
var modal_offset = modal_body.scrollTop();
$(el).css('height', 'auto').css('height', el.scrollHeight + offset); $(el).css('height', 'auto').css('height', el.scrollHeight + offset);
modal_body.scrollTop(modal_offset);
}; };
$(this).on('focus keyup input', function () { resizeTextarea(this); }).removeAttr('data-autoresize'); $(this).on('focus keyup input', function () { resizeTextarea(this); }).removeAttr('data-autoresize');
}); });

View file

@ -811,9 +811,12 @@
// auto resizing textarea for custom notification message body // auto resizing textarea for custom notification message body
$('textarea[data-autoresize]').each(function () { $('textarea[data-autoresize]').each(function () {
var modal_body = $(this).closest('.modal-body');
var offset = this.offsetHeight - this.clientHeight; var offset = this.offsetHeight - this.clientHeight;
var resizeTextarea = function (el) { var resizeTextarea = function (el) {
var modal_offset = modal_body.scrollTop();
$(el).css('height', 'auto').css('height', el.scrollHeight + offset); $(el).css('height', 'auto').css('height', el.scrollHeight + offset);
modal_body.scrollTop(modal_offset);
}; };
$(this).on('focus keyup input', function () { resizeTextarea(this); }).removeAttr('data-autoresize'); $(this).on('focus keyup input', function () { resizeTextarea(this); }).removeAttr('data-autoresize');
}); });