@danderson00/react-forms 0.0.23 → 0.0.26
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.
- package/dist/input.js +27 -4
- package/dist/inputTypes.js +2 -2
- package/package.json +1 -1
- package/src/input.js +19 -2
- package/src/inputTypes.js +4 -2
package/dist/input.js
CHANGED
|
@@ -111,7 +111,7 @@ var _default = function _default(render) {
|
|
|
111
111
|
if (value !== previousValueProp) {
|
|
112
112
|
setFieldValue(name, applyValueTransforms(value));
|
|
113
113
|
}
|
|
114
|
-
}, [props]);
|
|
114
|
+
}, [props]); // TODO: refactor bubbling to prop pattern
|
|
115
115
|
|
|
116
116
|
var onChange = function onChange() {
|
|
117
117
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -196,6 +196,25 @@ var _default = function _default(render) {
|
|
|
196
196
|
}
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
+
var onKeyDown = function onKeyDown() {
|
|
200
|
+
var onKeyDown = props.onKeyDown;
|
|
201
|
+
|
|
202
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
203
|
+
args[_key4] = arguments[_key4];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
var event = args[0];
|
|
207
|
+
var element = event.target;
|
|
208
|
+
|
|
209
|
+
if (props.numeric && !/[0-9-]/.exec(event.key) && ![null, 0, 8, 9, 13, 27, 35, 36, 37, 39, 46].includes(event.keyCode)) {
|
|
210
|
+
event.preventDefault();
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (onKeyDown) {
|
|
214
|
+
onKeyDown.apply(element, args);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
|
|
199
218
|
var updateValidationState = function updateValidationState() {
|
|
200
219
|
setFieldValidated(true); // this is a little hacky, but the simplest way I could think of to determine the
|
|
201
220
|
// validity of the actual input element. :invalid is also not supported by enzyme
|
|
@@ -232,6 +251,9 @@ var _default = function _default(render) {
|
|
|
232
251
|
var valueProps = getValueProps({
|
|
233
252
|
currentValue: getFieldValue(name)
|
|
234
253
|
});
|
|
254
|
+
var numericProps = numeric && {
|
|
255
|
+
type: 'number'
|
|
256
|
+
};
|
|
235
257
|
var typeProps = type && {
|
|
236
258
|
type: type
|
|
237
259
|
};
|
|
@@ -240,14 +262,15 @@ var _default = function _default(render) {
|
|
|
240
262
|
};
|
|
241
263
|
var className = (fieldValidated ? 'validated ' : '') + (props.className || '') || undefined;
|
|
242
264
|
|
|
243
|
-
var finalProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
265
|
+
var finalProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
244
266
|
id: id,
|
|
245
267
|
name: name,
|
|
246
268
|
className: className
|
|
247
|
-
}, passThroughProps), valueProps), typeProps), errorProps), {}, {
|
|
269
|
+
}, passThroughProps), valueProps), numericProps), typeProps), errorProps), {}, {
|
|
248
270
|
onChange: onChange,
|
|
249
271
|
onFocus: onFocus,
|
|
250
|
-
onBlur: onBlur
|
|
272
|
+
onBlur: onBlur,
|
|
273
|
+
onKeyDown: onKeyDown
|
|
251
274
|
});
|
|
252
275
|
|
|
253
276
|
return render(finalProps);
|
package/dist/inputTypes.js
CHANGED
|
@@ -22,7 +22,7 @@ var _default = function _default(props, options) {
|
|
|
22
22
|
defaultValue = props.defaultValue;
|
|
23
23
|
|
|
24
24
|
var applyValueTransforms = function applyValueTransforms(value) {
|
|
25
|
-
return props.type === 'number' || props.numeric ? +value : value;
|
|
25
|
+
return (props.type === 'number' || props.numeric) && !isNaN(+value) && value !== '' ? +value : value;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
var defaultType = {
|
|
@@ -53,7 +53,7 @@ var _default = function _default(props, options) {
|
|
|
53
53
|
getValueProps: function getValueProps(_ref3) {
|
|
54
54
|
var currentValue = _ref3.currentValue;
|
|
55
55
|
return {
|
|
56
|
-
value: currentValue
|
|
56
|
+
value: currentValue === undefined ? '' : currentValue
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
};
|
package/package.json
CHANGED
package/src/input.js
CHANGED
|
@@ -51,6 +51,7 @@ export default (render, options = {}) => function Input(props) {
|
|
|
51
51
|
}
|
|
52
52
|
}, [props])
|
|
53
53
|
|
|
54
|
+
// TODO: refactor bubbling to prop pattern
|
|
54
55
|
const onChange = (...args) => {
|
|
55
56
|
const [event] = args
|
|
56
57
|
const { name, setFieldValue, onChange, submitOnChange } = props
|
|
@@ -110,6 +111,21 @@ export default (render, options = {}) => function Input(props) {
|
|
|
110
111
|
}
|
|
111
112
|
}
|
|
112
113
|
|
|
114
|
+
const onKeyDown = (...args) => {
|
|
115
|
+
const { onKeyDown } = props
|
|
116
|
+
const [event] = args
|
|
117
|
+
const element = event.target
|
|
118
|
+
|
|
119
|
+
if(props.numeric && !/[0-9-]/.exec(event.key) && ![null, 0, 8, 9, 13, 27, 35, 36, 37, 39, 46].includes(event.keyCode)) {
|
|
120
|
+
event.preventDefault()
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if(onKeyDown) {
|
|
124
|
+
onKeyDown.apply(element, args)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
113
129
|
const updateValidationState = () => {
|
|
114
130
|
setFieldValidated(true)
|
|
115
131
|
// this is a little hacky, but the simplest way I could think of to determine the
|
|
@@ -128,14 +144,15 @@ export default (render, options = {}) => function Input(props) {
|
|
|
128
144
|
...passThroughProps
|
|
129
145
|
} = props
|
|
130
146
|
const valueProps = getValueProps({ currentValue: getFieldValue(name) })
|
|
147
|
+
const numericProps = (numeric && { type: 'number' })
|
|
131
148
|
const typeProps = (type && { type })
|
|
132
149
|
const errorProps = (passErrorProp && { error })
|
|
133
150
|
const className = ((fieldValidated ? 'validated ' : '') + (props.className || '') || undefined)
|
|
134
151
|
|
|
135
152
|
const finalProps = {
|
|
136
153
|
id, name, className,
|
|
137
|
-
...passThroughProps, ...valueProps, ...typeProps, ...errorProps,
|
|
138
|
-
onChange, onFocus, onBlur
|
|
154
|
+
...passThroughProps, ...valueProps, ...numericProps, ...typeProps, ...errorProps,
|
|
155
|
+
onChange, onFocus, onBlur, onKeyDown
|
|
139
156
|
}
|
|
140
157
|
|
|
141
158
|
return render(finalProps)
|
package/src/inputTypes.js
CHANGED
|
@@ -3,7 +3,7 @@ const resolveValue = (value, args) => typeof value === 'function' ? value.apply(
|
|
|
3
3
|
export default (props, options) => {
|
|
4
4
|
const { type, checked, value, defaultValue } = props
|
|
5
5
|
|
|
6
|
-
const applyValueTransforms = value => (props.type === 'number' || props.numeric) ? +value : value
|
|
6
|
+
const applyValueTransforms = value => ((props.type === 'number' || props.numeric) && !isNaN(+value) && value !== '') ? +value : value
|
|
7
7
|
|
|
8
8
|
const defaultType = {
|
|
9
9
|
setInitialValue: ({ set }) => {
|
|
@@ -26,7 +26,9 @@ export default (props, options) => {
|
|
|
26
26
|
throw new Error("Unable to determine input value from event")
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
|
-
getValueProps: ({ currentValue }) => ({
|
|
29
|
+
getValueProps: ({ currentValue }) => ({
|
|
30
|
+
value: currentValue === undefined ? '' : currentValue
|
|
31
|
+
})
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
const checkboxValue = (checked, value) => (value === undefined
|