@symply.io/basic-components 1.5.4 → 1.5.5-alpha.1
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/NumberInput/useInteractions.js +16 -10
- package/package.json +1 -1
@@ -3,6 +3,7 @@ function useInteractions(props) {
|
|
3
3
|
var value = props.value, _a = props.decimals, decimals = _a === void 0 ? 0 : _a, integerOnly = props.integerOnly, _b = props.minValue, minValue = _b === void 0 ? Number.MIN_SAFE_INTEGER : _b, _c = props.maxValue, maxValue = _c === void 0 ? Number.MAX_SAFE_INTEGER : _c, onChange = props.onChange;
|
4
4
|
var _d = useState(false), tooltipOpen = _d[0], setTooltipOpen = _d[1];
|
5
5
|
var _e = useState(false), typing = _e[0], setTyping = _e[1];
|
6
|
+
var _f = useState(value), register = _f[0], setRegister = _f[1];
|
6
7
|
var roundedValue = useMemo(function () {
|
7
8
|
if (value === null || value === undefined) {
|
8
9
|
return "";
|
@@ -25,7 +26,7 @@ function useInteractions(props) {
|
|
25
26
|
}, [value, decimals]);
|
26
27
|
var exceedError = useMemo(function () { return !!value && (Number(value) < minValue || Number(value) > maxValue); }, [value, minValue, maxValue]);
|
27
28
|
var handleKeyboardEvent = useCallback(function (event) {
|
28
|
-
var key = event.key;
|
29
|
+
var key = event.key, currentTarget = event.currentTarget;
|
29
30
|
if (key === "e") {
|
30
31
|
event.preventDefault();
|
31
32
|
}
|
@@ -42,16 +43,20 @@ function useInteractions(props) {
|
|
42
43
|
event.preventDefault();
|
43
44
|
}
|
44
45
|
else if (String(value).includes(".") && decimals > 0) {
|
46
|
+
var decimalPointIndex = String(value).lastIndexOf(".");
|
45
47
|
var decimalStrLen = String(value).split(".")[1].length;
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
48
|
+
var selectionStart = currentTarget.selectionStart;
|
49
|
+
if (selectionStart && decimalPointIndex <= selectionStart) {
|
50
|
+
if (![
|
51
|
+
"Backspace",
|
52
|
+
"ArrowUp",
|
53
|
+
"ArrowDown",
|
54
|
+
"ArrowLeft",
|
55
|
+
"ArrowRight"
|
56
|
+
].includes(key) &&
|
57
|
+
decimalStrLen >= decimals) {
|
58
|
+
event.preventDefault();
|
59
|
+
}
|
55
60
|
}
|
56
61
|
}
|
57
62
|
}
|
@@ -71,6 +76,7 @@ function useInteractions(props) {
|
|
71
76
|
}, [onChange, minValue, integerOnly]);
|
72
77
|
var handleFocus = useCallback(function () {
|
73
78
|
setTyping(true);
|
79
|
+
setRegister(value);
|
74
80
|
}, [value]);
|
75
81
|
var handleBlur = useCallback(function () {
|
76
82
|
var excludedValue = [
|