Input.js
3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
var React = _interopRequireWildcard(require("react"));
var _ref2 = require("rc-util/lib/ref");
var Input = function Input(_ref, ref) {
var prefixCls = _ref.prefixCls,
id = _ref.id,
inputElement = _ref.inputElement,
disabled = _ref.disabled,
tabIndex = _ref.tabIndex,
autoFocus = _ref.autoFocus,
autoComplete = _ref.autoComplete,
editable = _ref.editable,
accessibilityIndex = _ref.accessibilityIndex,
value = _ref.value,
maxLength = _ref.maxLength,
_onKeyDown = _ref.onKeyDown,
_onMouseDown = _ref.onMouseDown,
_onChange = _ref.onChange,
onPaste = _ref.onPaste,
_onCompositionStart = _ref.onCompositionStart,
_onCompositionEnd = _ref.onCompositionEnd,
open = _ref.open,
attrs = _ref.attrs;
var inputNode = inputElement || React.createElement("input", null);
var _inputNode = inputNode,
originRef = _inputNode.ref,
_inputNode$props = _inputNode.props,
onOriginKeyDown = _inputNode$props.onKeyDown,
onOriginChange = _inputNode$props.onChange,
onOriginMouseDown = _inputNode$props.onMouseDown,
onOriginCompositionStart = _inputNode$props.onCompositionStart,
onOriginCompositionEnd = _inputNode$props.onCompositionEnd,
style = _inputNode$props.style;
inputNode = React.cloneElement(inputNode, (0, _objectSpread2.default)((0, _objectSpread2.default)({
id: id,
ref: (0, _ref2.composeRef)(ref, originRef),
disabled: disabled,
tabIndex: tabIndex,
autoComplete: autoComplete || 'off',
type: 'search',
autoFocus: autoFocus,
className: "".concat(prefixCls, "-selection-search-input"),
style: (0, _objectSpread2.default)((0, _objectSpread2.default)({}, style), {}, {
opacity: editable ? null : 0
}),
role: 'combobox',
'aria-expanded': open,
'aria-haspopup': 'listbox',
'aria-owns': "".concat(id, "_list"),
'aria-autocomplete': 'list',
'aria-controls': "".concat(id, "_list"),
'aria-activedescendant': "".concat(id, "_list_").concat(accessibilityIndex)
}, attrs), {}, {
value: editable ? value : '',
maxLength: maxLength,
readOnly: !editable,
unselectable: !editable ? 'on' : null,
onKeyDown: function onKeyDown(event) {
_onKeyDown(event);
if (onOriginKeyDown) {
onOriginKeyDown(event);
}
},
onMouseDown: function onMouseDown(event) {
_onMouseDown(event);
if (onOriginMouseDown) {
onOriginMouseDown(event);
}
},
onChange: function onChange(event) {
_onChange(event);
if (onOriginChange) {
onOriginChange(event);
}
},
onCompositionStart: function onCompositionStart(event) {
_onCompositionStart(event);
if (onOriginCompositionStart) {
onOriginCompositionStart(event);
}
},
onCompositionEnd: function onCompositionEnd(event) {
_onCompositionEnd(event);
if (onOriginCompositionEnd) {
onOriginCompositionEnd(event);
}
},
onPaste: onPaste
}));
return inputNode;
};
var RefInput = React.forwardRef(Input);
RefInput.displayName = 'Input';
var _default = RefInput;
exports.default = _default;