Input.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import _extends from "@babel/runtime/helpers/esm/extends";
  3. import { createVNode as _createVNode } from "vue";
  4. import { cloneElement } from '../../_util/vnode';
  5. import { defineComponent, inject, withDirectives } from 'vue';
  6. import PropTypes from '../../_util/vue-types';
  7. import antInput from '../../_util/antInputDirective';
  8. import classNames from '../../_util/classNames';
  9. export var inputProps = {
  10. inputRef: PropTypes.any,
  11. prefixCls: String,
  12. id: String,
  13. inputElement: PropTypes.VueNode,
  14. disabled: {
  15. type: Boolean,
  16. default: undefined
  17. },
  18. autofocus: {
  19. type: Boolean,
  20. default: undefined
  21. },
  22. autocomplete: String,
  23. editable: {
  24. type: Boolean,
  25. default: undefined
  26. },
  27. activeDescendantId: String,
  28. value: String,
  29. open: {
  30. type: Boolean,
  31. default: undefined
  32. },
  33. tabindex: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
  34. /** Pass accessibility props to input */
  35. attrs: PropTypes.object,
  36. onKeydown: {
  37. type: Function
  38. },
  39. onMousedown: {
  40. type: Function
  41. },
  42. onChange: {
  43. type: Function
  44. },
  45. onPaste: {
  46. type: Function
  47. },
  48. onCompositionstart: {
  49. type: Function
  50. },
  51. onCompositionend: {
  52. type: Function
  53. },
  54. onFocus: {
  55. type: Function
  56. },
  57. onBlur: {
  58. type: Function
  59. }
  60. };
  61. var Input = defineComponent({
  62. compatConfig: {
  63. MODE: 3
  64. },
  65. name: 'Input',
  66. inheritAttrs: false,
  67. props: inputProps,
  68. setup: function setup(props) {
  69. var blurTimeout = null;
  70. var VCSelectContainerEvent = inject('VCSelectContainerEvent');
  71. return function () {
  72. var _inputNode, _inputNode$props;
  73. var prefixCls = props.prefixCls,
  74. id = props.id,
  75. inputElement = props.inputElement,
  76. disabled = props.disabled,
  77. tabindex = props.tabindex,
  78. autofocus = props.autofocus,
  79. autocomplete = props.autocomplete,
  80. editable = props.editable,
  81. activeDescendantId = props.activeDescendantId,
  82. value = props.value,
  83. _onKeydown = props.onKeydown,
  84. _onMousedown = props.onMousedown,
  85. onChange = props.onChange,
  86. onPaste = props.onPaste,
  87. _onCompositionstart = props.onCompositionstart,
  88. _onCompositionend = props.onCompositionend,
  89. _onFocus = props.onFocus,
  90. _onBlur = props.onBlur,
  91. open = props.open,
  92. inputRef = props.inputRef,
  93. attrs = props.attrs;
  94. var inputNode = inputElement || withDirectives(_createVNode("input", null, null), [[antInput]]);
  95. var inputProps = inputNode.props || {};
  96. var onOriginKeyDown = inputProps.onKeydown,
  97. onOriginInput = inputProps.onInput,
  98. onOriginFocus = inputProps.onFocus,
  99. onOriginBlur = inputProps.onBlur,
  100. onOriginMouseDown = inputProps.onMousedown,
  101. onOriginCompositionStart = inputProps.onCompositionstart,
  102. onOriginCompositionEnd = inputProps.onCompositionend,
  103. style = inputProps.style;
  104. inputNode = cloneElement(inputNode, _extends(_objectSpread(_objectSpread(_objectSpread({
  105. type: 'search'
  106. }, inputProps), {}, {
  107. id: id,
  108. ref: inputRef,
  109. disabled: disabled,
  110. tabindex: tabindex,
  111. autocomplete: autocomplete || 'off',
  112. autofocus: autofocus,
  113. class: classNames("".concat(prefixCls, "-selection-search-input"), (_inputNode = inputNode) === null || _inputNode === void 0 ? void 0 : (_inputNode$props = _inputNode.props) === null || _inputNode$props === void 0 ? void 0 : _inputNode$props.class),
  114. role: 'combobox',
  115. 'aria-expanded': open,
  116. 'aria-haspopup': 'listbox',
  117. 'aria-owns': "".concat(id, "_list"),
  118. 'aria-autocomplete': 'list',
  119. 'aria-controls': "".concat(id, "_list"),
  120. 'aria-activedescendant': activeDescendantId
  121. }, attrs), {}, {
  122. value: editable ? value : '',
  123. readonly: !editable,
  124. unselectable: !editable ? 'on' : null,
  125. style: _objectSpread(_objectSpread({}, style), {}, {
  126. opacity: editable ? null : 0
  127. }),
  128. onKeydown: function onKeydown(event) {
  129. _onKeydown(event);
  130. if (onOriginKeyDown) {
  131. onOriginKeyDown(event);
  132. }
  133. },
  134. onMousedown: function onMousedown(event) {
  135. _onMousedown(event);
  136. if (onOriginMouseDown) {
  137. onOriginMouseDown(event);
  138. }
  139. },
  140. onInput: function onInput(event) {
  141. onChange(event);
  142. if (onOriginInput) {
  143. onOriginInput(event);
  144. }
  145. },
  146. onCompositionstart: function onCompositionstart(event) {
  147. _onCompositionstart(event);
  148. if (onOriginCompositionStart) {
  149. onOriginCompositionStart(event);
  150. }
  151. },
  152. onCompositionend: function onCompositionend(event) {
  153. _onCompositionend(event);
  154. if (onOriginCompositionEnd) {
  155. onOriginCompositionEnd(event);
  156. }
  157. },
  158. onPaste: onPaste,
  159. onFocus: function onFocus() {
  160. clearTimeout(blurTimeout);
  161. onOriginFocus && onOriginFocus(arguments.length <= 0 ? undefined : arguments[0]);
  162. _onFocus && _onFocus(arguments.length <= 0 ? undefined : arguments[0]);
  163. VCSelectContainerEvent === null || VCSelectContainerEvent === void 0 ? void 0 : VCSelectContainerEvent.focus(arguments.length <= 0 ? undefined : arguments[0]);
  164. },
  165. onBlur: function onBlur() {
  166. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  167. args[_key] = arguments[_key];
  168. }
  169. blurTimeout = setTimeout(function () {
  170. onOriginBlur && onOriginBlur(args[0]);
  171. _onBlur && _onBlur(args[0]);
  172. VCSelectContainerEvent === null || VCSelectContainerEvent === void 0 ? void 0 : VCSelectContainerEvent.blur(args[0]);
  173. }, 100);
  174. }
  175. }), inputNode.type === 'textarea' ? {} : {
  176. type: 'search'
  177. }), true, true);
  178. return inputNode;
  179. };
  180. }
  181. });
  182. export default Input;