Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VTextarea.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  2. // Styles
  3. import '../../../src/stylus/components/_textarea.styl';
  4. // Extensions
  5. import VTextField from '../VTextField/VTextField';
  6. import { consoleInfo } from '../../util/console';
  7. /* @vue/component */
  8. export default {
  9. name: 'v-textarea',
  10. extends: VTextField,
  11. props: {
  12. autoGrow: Boolean,
  13. noResize: Boolean,
  14. outline: Boolean,
  15. rowHeight: {
  16. type: [Number, String],
  17. default: 24,
  18. validator: function validator(v) {
  19. return !isNaN(parseFloat(v));
  20. }
  21. },
  22. rows: {
  23. type: [Number, String],
  24. default: 5,
  25. validator: function validator(v) {
  26. return !isNaN(parseInt(v, 10));
  27. }
  28. }
  29. },
  30. computed: {
  31. classes: function classes() {
  32. return _extends({
  33. 'v-textarea': true,
  34. 'v-textarea--auto-grow': this.autoGrow,
  35. 'v-textarea--no-resize': this.noResizeHandle
  36. }, VTextField.options.computed.classes.call(this, null));
  37. },
  38. dynamicHeight: function dynamicHeight() {
  39. return this.autoGrow ? this.inputHeight : 'auto';
  40. },
  41. isEnclosed: function isEnclosed() {
  42. return this.textarea || VTextField.options.computed.isEnclosed.call(this);
  43. },
  44. noResizeHandle: function noResizeHandle() {
  45. return this.noResize || this.autoGrow;
  46. }
  47. },
  48. watch: {
  49. lazyValue: function lazyValue() {
  50. !this.internalChange && this.autoGrow && this.$nextTick(this.calculateInputHeight);
  51. }
  52. },
  53. mounted: function mounted() {
  54. var _this = this;
  55. setTimeout(function () {
  56. _this.autoGrow && _this.calculateInputHeight();
  57. }, 0);
  58. // TODO: remove (2.0)
  59. if (this.autoGrow && this.noResize) {
  60. consoleInfo('"no-resize" is now implied when using "auto-grow", and can be removed', this);
  61. }
  62. },
  63. methods: {
  64. calculateInputHeight: function calculateInputHeight() {
  65. var input = this.$refs.input;
  66. if (input) {
  67. input.style.height = 0;
  68. var height = input.scrollHeight;
  69. var minHeight = parseInt(this.rows, 10) * parseFloat(this.rowHeight);
  70. // This has to be done ASAP, waiting for Vue
  71. // to update the DOM causes ugly layout jumping
  72. input.style.height = Math.max(minHeight, height) + 'px';
  73. }
  74. },
  75. genInput: function genInput() {
  76. var input = VTextField.options.methods.genInput.call(this);
  77. input.tag = 'textarea';
  78. delete input.data.attrs.type;
  79. input.data.attrs.rows = this.rows;
  80. return input;
  81. },
  82. onInput: function onInput(e) {
  83. VTextField.options.methods.onInput.call(this, e);
  84. this.autoGrow && this.calculateInputHeight();
  85. },
  86. onKeyDown: function onKeyDown(e) {
  87. // Prevents closing of a
  88. // dialog when pressing
  89. // enter
  90. if (this.isFocused && e.keyCode === 13) {
  91. e.stopPropagation();
  92. }
  93. this.internalChange = true;
  94. this.$emit('keydown', e);
  95. }
  96. }
  97. };
  98. //# sourceMappingURL=VTextarea.js.map