index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. 'use strict';
  2. var __assign =
  3. (this && this.__assign) ||
  4. function () {
  5. __assign =
  6. Object.assign ||
  7. function (t) {
  8. for (var s, i = 1, n = arguments.length; i < n; i++) {
  9. s = arguments[i];
  10. for (var p in s)
  11. if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  12. }
  13. return t;
  14. };
  15. return __assign.apply(this, arguments);
  16. };
  17. Object.defineProperty(exports, '__esModule', { value: true });
  18. var utils_1 = require('../common/utils');
  19. var component_1 = require('../common/component');
  20. var props_1 = require('./props');
  21. component_1.VantComponent({
  22. field: true,
  23. classes: ['input-class', 'right-icon-class', 'label-class'],
  24. props: __assign(
  25. __assign(
  26. __assign(__assign({}, props_1.commonProps), props_1.inputProps),
  27. props_1.textareaProps
  28. ),
  29. {
  30. size: String,
  31. icon: String,
  32. label: String,
  33. error: Boolean,
  34. center: Boolean,
  35. isLink: Boolean,
  36. leftIcon: String,
  37. rightIcon: String,
  38. autosize: null,
  39. required: Boolean,
  40. iconClass: String,
  41. clickable: Boolean,
  42. inputAlign: String,
  43. customStyle: String,
  44. errorMessage: String,
  45. arrowDirection: String,
  46. showWordLimit: Boolean,
  47. errorMessageAlign: String,
  48. readonly: {
  49. type: Boolean,
  50. observer: 'setShowClear',
  51. },
  52. clearable: {
  53. type: Boolean,
  54. observer: 'setShowClear',
  55. },
  56. clearTrigger: {
  57. type: String,
  58. value: 'focus',
  59. },
  60. border: {
  61. type: Boolean,
  62. value: true,
  63. },
  64. titleWidth: {
  65. type: String,
  66. value: '6.2em',
  67. },
  68. clearIcon: {
  69. type: String,
  70. value: 'clear',
  71. },
  72. }
  73. ),
  74. data: {
  75. focused: false,
  76. innerValue: '',
  77. showClear: false,
  78. },
  79. created: function () {
  80. this.value = this.data.value;
  81. this.setData({ innerValue: this.value });
  82. },
  83. methods: {
  84. onInput: function (event) {
  85. var _a = (event.detail || {}).value,
  86. value = _a === void 0 ? '' : _a;
  87. this.value = value;
  88. this.setShowClear();
  89. this.emitChange();
  90. },
  91. onFocus: function (event) {
  92. this.focused = true;
  93. this.setShowClear();
  94. this.$emit('focus', event.detail);
  95. },
  96. onBlur: function (event) {
  97. this.focused = false;
  98. this.setShowClear();
  99. this.$emit('blur', event.detail);
  100. },
  101. onClickIcon: function () {
  102. this.$emit('click-icon');
  103. },
  104. onClickInput: function (event) {
  105. this.$emit('click-input', event.detail);
  106. },
  107. onClear: function () {
  108. var _this = this;
  109. this.setData({ innerValue: '' });
  110. this.value = '';
  111. this.setShowClear();
  112. utils_1.nextTick(function () {
  113. _this.emitChange();
  114. _this.$emit('clear', '');
  115. });
  116. },
  117. onConfirm: function (event) {
  118. var _a = (event.detail || {}).value,
  119. value = _a === void 0 ? '' : _a;
  120. this.value = value;
  121. this.setShowClear();
  122. this.$emit('confirm', value);
  123. },
  124. setValue: function (value) {
  125. this.value = value;
  126. this.setShowClear();
  127. if (value === '') {
  128. this.setData({ innerValue: '' });
  129. }
  130. this.emitChange();
  131. },
  132. onLineChange: function (event) {
  133. this.$emit('linechange', event.detail);
  134. },
  135. onKeyboardHeightChange: function (event) {
  136. this.$emit('keyboardheightchange', event.detail);
  137. },
  138. emitChange: function () {
  139. var _this = this;
  140. this.setData({ value: this.value });
  141. utils_1.nextTick(function () {
  142. _this.$emit('input', _this.value);
  143. _this.$emit('change', _this.value);
  144. });
  145. },
  146. setShowClear: function () {
  147. var _a = this.data,
  148. clearable = _a.clearable,
  149. readonly = _a.readonly,
  150. clearTrigger = _a.clearTrigger;
  151. var _b = this,
  152. focused = _b.focused,
  153. value = _b.value;
  154. var showClear = false;
  155. if (clearable && !readonly) {
  156. var hasValue = !!value;
  157. var trigger =
  158. clearTrigger === 'always' || (clearTrigger === 'focus' && focused);
  159. showClear = hasValue && trigger;
  160. }
  161. this.setData({ showClear: showClear });
  162. },
  163. noop: function () {},
  164. },
  165. });