Skip to content

Commit

Permalink
fix(mail(js)): bypass autogrow feature of md-input to fix scroll jumping
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed Jan 20, 2020
1 parent 560c1dc commit 73dc86a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions UI/Templates/MailerUI/UIxMailEditor.wox
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@
ng-focus="editor.onTextFocus($event)"
md-autofocus="::!editor.isNew()"
md-no-resize="md-no-resize"
md-no-autogrow="md-no-autogrow"
sg-autogrow="sg-autogrow"
md-detect-hidden="md-detect-hidden" />
</md-input-container>
</md-dialog-content>
Expand Down
51 changes: 51 additions & 0 deletions UI/WebServerResources/js/Common/sgAutogrow.directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* -*- Mode: javascript; indent-tabs-mode: nil; c-basic-offset: 2 -*- */

(function() {
'use strict';

/**
* sgAutogrow - A directive to automatically grow a textarea depending on its content.
* This directive is an alternative to the autogrow feature of the md-input component.
* It fixes the scroll jumping issue described in #3070.
*
* - https://github.com/angular/material/issues/3070
* - https://material.angularjs.org/latest/api/directive/mdInput
*
* The drawback of this simple fix is that it won't shrink the textarea but only
* increase its height. It also requires to set md-no-autogrow.
* @memberof SOGo.Common
* @ngInject
* @example:
<textarea rows="9" md-no-autogrow sg-autogrow />
*/
sgAutogrow.$inject = ['$timeout'];
function sgAutogrow($timeout) {
return {
restrict: 'A',
link: function(scope, elem, attr) {
var textarea = elem[0];

function AutoGrowTextArea() {
$timeout(function() {
if (textarea.clientHeight < textarea.scrollHeight) {
textarea.style.height = textarea.scrollHeight + 'px';
if (textarea.clientHeight < textarea.scrollHeight) {
textarea.style.height = (textarea.scrollHeight * 2 - textarea.clientHeight) + 'px';
}
}
});
}

textarea.style.overflow = 'hidden';

elem.on('keyup', AutoGrowTextArea);
elem.on('paste', AutoGrowTextArea);
}
};
}

angular
.module('SOGo.Common')
.directive('sgAutogrow', sgAutogrow);
})();

0 comments on commit 73dc86a

Please sign in to comment.