@longline/aqua-ui 1.0.334 → 1.0.335
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/inputs/DateInput/Selector.js +17 -10
- package/package.json +1 -1
|
@@ -23,18 +23,25 @@ var Selector = function (props) {
|
|
|
23
23
|
setYear(props.value ? props.value.getFullYear().toString() : "");
|
|
24
24
|
}
|
|
25
25
|
}, [props.value]);
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
// Emit synchronously from the onChange handler rather than via a useEffect
|
|
27
|
+
// on [day, month, year]. Passive effects don't run until after paint, so
|
|
28
|
+
// an effect-based emit can be skipped if the next browser event (e.g. a
|
|
29
|
+
// click on Save) arrives before React's effect phase — losing the
|
|
30
|
+
// most-recent keystroke.
|
|
31
|
+
var emit = function (d, m, y) {
|
|
32
|
+
var numDay = parseInt(d);
|
|
33
|
+
var numMonth = parseInt(m);
|
|
34
|
+
var numYear = parseInt(y);
|
|
35
|
+
if (isNaN(numDay) || isNaN(numMonth) || isNaN(numYear))
|
|
32
36
|
return;
|
|
33
37
|
var date = new Date(numYear, numMonth - 1, numDay);
|
|
34
38
|
// Overwrite year, because Date.new converts 0-99 to 1900-1999.
|
|
35
39
|
date.setFullYear(numYear);
|
|
36
40
|
props.onChange(date);
|
|
37
|
-
}
|
|
41
|
+
};
|
|
42
|
+
var handleDayChange = function (v) { setDay(v); emit(v, month, year); };
|
|
43
|
+
var handleMonthChange = function (v) { setMonth(v); emit(day, v, year); };
|
|
44
|
+
var handleYearChange = function (v) { setYear(v); emit(day, month, v); };
|
|
38
45
|
// Move focus to month input.
|
|
39
46
|
var focusMonth = function () {
|
|
40
47
|
monthRef.current.focus();
|
|
@@ -46,10 +53,10 @@ var Selector = function (props) {
|
|
|
46
53
|
yearRef.current.select();
|
|
47
54
|
};
|
|
48
55
|
return (React.createElement(InputWrapper, { fluid: true, error: props.error, disabled: props.disabled, ghost: props.ghost, transparent: props.transparent, onClear: (props.clearable && props.value) ? props.onClear : null, icon: { url: SVG.Icons.Calendar, color: theme.colors.primary[3], onClick: props.onCalendar }, iconPosition: 'right' },
|
|
49
|
-
React.createElement(NumericInput, { disabled: props.disabled, width: 38, maxLength: 2, placeholder: "dd", value: day, onChange:
|
|
56
|
+
React.createElement(NumericInput, { disabled: props.disabled, width: 38, maxLength: 2, placeholder: "dd", value: day, onChange: handleDayChange, onBlur: focusMonth }),
|
|
50
57
|
"/",
|
|
51
|
-
React.createElement(NumericInput, { disabled: props.disabled, width: 38, maxLength: 2, placeholder: "mm", value: month, onChange:
|
|
58
|
+
React.createElement(NumericInput, { disabled: props.disabled, width: 38, maxLength: 2, placeholder: "mm", value: month, onChange: handleMonthChange, ref: monthRef, onBlur: focusYear }),
|
|
52
59
|
"/",
|
|
53
|
-
React.createElement(NumericInput, { disabled: props.disabled, width: 44, maxLength: 4, placeholder: "yyyy", value: year, onChange:
|
|
60
|
+
React.createElement(NumericInput, { disabled: props.disabled, width: 44, maxLength: 4, placeholder: "yyyy", value: year, onChange: handleYearChange, ref: yearRef })));
|
|
54
61
|
};
|
|
55
62
|
export { Selector };
|