expandableTextArea.js 955 B

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