expandableTextArea.js 902 B

1234567891011121314151617181920212223242526272829
  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', () => ({
  10. restrict: 'A',
  11. link(scope, el) {
  12. const resetHeight = function () {
  13. const curHeight = el.outerHeight()
  14. const fitHeight = el.prop('scrollHeight')
  15. // clear height if text area is empty
  16. if (el.val() === '') {
  17. el.css('height', 'unset')
  18. }
  19. // otherwise expand to fit text
  20. else if (fitHeight > curHeight) {
  21. scope.$emit('expandable-text-area:resize')
  22. el.css('height', fitHeight)
  23. }
  24. }
  25. return scope.$watch(() => el.val(), resetHeight)
  26. },
  27. }))