Skip to content

Commit

Permalink
fix(mail(js)): disable autogrow of textarea in popup window
Browse files Browse the repository at this point in the history
Fixes #4962
  • Loading branch information
cgx committed Feb 21, 2020
1 parent 5e1f487 commit daaad93
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions UI/Templates/MailerUI/UIxMailEditor.wox
Expand Up @@ -274,13 +274,13 @@
md-autofocus="::!editor.isNew()"
md-no-resize="md-no-resize"
md-no-autogrow="md-no-autogrow"
sg-autogrow="sg-autogrow"
sg-autogrow="!isPopup"
md-detect-hidden="md-detect-hidden" />
</md-input-container>
</md-dialog-content>

<!-- ATTACHMENTS -->
<md-dialog-content class="md-actions sg-mail-editor-attachments"
<md-dialog-actions class="sg-mail-editor-attachments"
layout="row" layout-align="space-between start">
<!-- Attachments -->
<md-chips ng-model="editor.uploader.queue"
Expand Down Expand Up @@ -311,7 +311,7 @@
-->
<!-- multiple="multiple" -->
</div>
</md-dialog-content>
</md-dialog-actions>
</form>

<sg-ripple class="md-default-theme md-accent md-bg"
Expand Down
13 changes: 8 additions & 5 deletions UI/WebServerResources/js/Common/sgAutogrow.directive.js
Expand Up @@ -4,26 +4,30 @@
'use strict';

/**
* sgAutogrow - A directive to automatically grow a textarea depending on its content.
* sgAutogrow - A directive to conditionally 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.
* The drawback of this directive is that it requires to set md-no-autogrow.
* @memberof SOGo.Common
* @ngInject
* @example:
<textarea rows="9" md-no-autogrow sg-autogrow />
<textarea rows="9" md-no-autogrow sg-autogrow="!isPopup" />
*/
sgAutogrow.$inject = ['$document', '$timeout'];
function sgAutogrow($document, $timeout) {
return {
restrict: 'A',
scope: {
autogrow: '=sgAutogrow'
},
link: function(scope, elem, attr) {
if (!scope.autogrow) return;

var textarea = elem[0];
var hiddenDiv = $document[0].createElement('div');
var content = null;
Expand All @@ -46,7 +50,6 @@
hiddenDiv.style.visibility = 'hidden';
hiddenDiv.style.display = 'block';
textarea.style.height = hiddenDiv.offsetHeight + 'px';
console.debug('resize to ' + hiddenDiv.offsetHeight + 'px');
hiddenDiv.style.visibility = 'visible';
hiddenDiv.style.display = 'none';
});
Expand Down

0 comments on commit daaad93

Please sign in to comment.