expandableTextArea.js 923 B

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