expandableTextArea.js 956 B

12345678910111213141516171819202122232425262728293031
  1. /* eslint-disable
  2. no-undef,
  3. */
  4. // TODO: This file was created by bulk-decaffeinate.
  5. // Fix any style issues and re-enable lint.
  6. /*
  7. * decaffeinate suggestions:
  8. * DS102: Remove unnecessary code created because of implicit returns
  9. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  10. */
  11. define(['base'], App =>
  12. App.directive('expandableTextArea', () => ({
  13. restrict: 'A',
  14. link(scope, el) {
  15. const resetHeight = function() {
  16. const curHeight = el.outerHeight()
  17. const fitHeight = el.prop('scrollHeight')
  18. // clear height if text area is empty
  19. if (el.val() === '') {
  20. el.css('height', 'unset')
  21. }
  22. // otherwise expand to fit text
  23. else if (fitHeight > curHeight) {
  24. scope.$emit('expandable-text-area:resize')
  25. el.css('height', fitHeight)
  26. }
  27. }
  28. return scope.$watch(() => el.val(), resetHeight)
  29. }
  30. })))