@invoicebox/ui 0.1.0-alpha.203 → 0.1.0-alpha.205
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -36,10 +36,11 @@ var TagsInput = exports.TagsInput = function TagsInput(_ref) {
|
|
|
36
36
|
value = _ref.value,
|
|
37
37
|
onChange = _ref.onChange,
|
|
38
38
|
palette = _ref.palette;
|
|
39
|
+
var newValueAutofillIntervalRef = (0, _react.useRef)(null);
|
|
39
40
|
var _useState = (0, _react.useState)(''),
|
|
40
41
|
_useState2 = _slicedToArray(_useState, 2),
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
inputValue = _useState2[0],
|
|
43
|
+
setInputValue = _useState2[1];
|
|
43
44
|
var _useInputFocus = (0, _useInputFocus2.useInputFocus)(),
|
|
44
45
|
inFocus = _useInputFocus.inFocus,
|
|
45
46
|
handleFocus = _useInputFocus.handleFocus,
|
|
@@ -50,13 +51,29 @@ var TagsInput = exports.TagsInput = function TagsInput(_ref) {
|
|
|
50
51
|
var _SIZE_PARAMS_MAP$size = _constants.SIZE_PARAMS_MAP[size],
|
|
51
52
|
paddingBottom = _SIZE_PARAMS_MAP$size.paddingBottom,
|
|
52
53
|
paddingTop = _SIZE_PARAMS_MAP$size.paddingTop;
|
|
53
|
-
var
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
var clearNewValueAutofillInterval = function clearNewValueAutofillInterval() {
|
|
55
|
+
if (newValueAutofillIntervalRef.current) {
|
|
56
|
+
clearInterval(newValueAutofillIntervalRef.current);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
var acceptNewValue = function acceptNewValue(newValue) {
|
|
60
|
+
onChange(value !== null && value !== void 0 && value.includes(newValue) ? value : [].concat(_toConsumableArray(value ? value : []), [newValue]));
|
|
61
|
+
setInputValue('');
|
|
62
|
+
};
|
|
63
|
+
var handleChange = function handleChange(event) {
|
|
64
|
+
setInputValue(event.target.value);
|
|
65
|
+
clearNewValueAutofillInterval();
|
|
66
|
+
if (event.target.value) {
|
|
67
|
+
newValueAutofillIntervalRef.current = setInterval(function () {
|
|
68
|
+
acceptNewValue(event.target.value);
|
|
69
|
+
}, 3000);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
56
72
|
var handleKeyDown = function handleKeyDown(event) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
73
|
+
var target = event.target;
|
|
74
|
+
if (event.key === 'Enter' && inputValue.length) {
|
|
75
|
+
clearNewValueAutofillInterval();
|
|
76
|
+
acceptNewValue(target.value);
|
|
60
77
|
}
|
|
61
78
|
};
|
|
62
79
|
var handleTagRemove = function handleTagRemove(tagRemoved) {
|
|
@@ -69,6 +86,13 @@ var TagsInput = exports.TagsInput = function TagsInput(_ref) {
|
|
|
69
86
|
var _inputRef$current;
|
|
70
87
|
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
|
|
71
88
|
};
|
|
89
|
+
var handlePureInputBlur = function handlePureInputBlur(event) {
|
|
90
|
+
handleBlur(event);
|
|
91
|
+
clearNewValueAutofillInterval();
|
|
92
|
+
if (event.target.value) {
|
|
93
|
+
acceptNewValue(event.target.value);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
72
96
|
return /*#__PURE__*/_react["default"].createElement(_InputLabel.InputLabel, {
|
|
73
97
|
label: label
|
|
74
98
|
}, /*#__PURE__*/_react["default"].createElement(S.PureInputStyledWrapper, {
|
|
@@ -106,10 +130,10 @@ var TagsInput = exports.TagsInput = function TagsInput(_ref) {
|
|
|
106
130
|
paddingTop: 0,
|
|
107
131
|
paddingLeft: 0,
|
|
108
132
|
borderRadius: 0,
|
|
109
|
-
value:
|
|
133
|
+
value: inputValue,
|
|
110
134
|
onChange: handleChange,
|
|
111
135
|
onKeyDown: handleKeyDown,
|
|
112
|
-
onBlur:
|
|
136
|
+
onBlur: handlePureInputBlur,
|
|
113
137
|
onFocus: handleFocus
|
|
114
138
|
})))));
|
|
115
139
|
};
|