@symply.io/basic-components 1.5.7-alpha.3 → 1.5.7-alpha.5
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 +19 -16
- package/package.json +1 -1
@@ -38,27 +38,26 @@ function useInteractions(props) {
|
|
38
38
|
event.preventDefault();
|
39
39
|
}
|
40
40
|
}
|
41
|
-
else if (String(val) === "0" && key !== ".") {
|
42
|
-
event.preventDefault();
|
43
|
-
}
|
44
41
|
else {
|
45
42
|
if (key === "-") {
|
46
43
|
event.preventDefault();
|
47
44
|
}
|
48
|
-
else
|
45
|
+
else {
|
49
46
|
var selectionStart = currentTarget.selectionStart;
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
if (
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
47
|
+
if (String(val).includes(".") && decimals > 0) {
|
48
|
+
var decimalPointIndex = String(val).lastIndexOf(".");
|
49
|
+
var decimalStrLen = String(val).split(".")[1].length;
|
50
|
+
if (selectionStart && decimalPointIndex < selectionStart) {
|
51
|
+
if (![
|
52
|
+
"Backspace",
|
53
|
+
"ArrowUp",
|
54
|
+
"ArrowDown",
|
55
|
+
"ArrowLeft",
|
56
|
+
"ArrowRight"
|
57
|
+
].includes(key) &&
|
58
|
+
decimalStrLen >= decimals) {
|
59
|
+
event.preventDefault();
|
60
|
+
}
|
62
61
|
}
|
63
62
|
}
|
64
63
|
}
|
@@ -100,6 +99,10 @@ function useInteractions(props) {
|
|
100
99
|
else if (excludedValue.includes(strVal)) {
|
101
100
|
onChange("");
|
102
101
|
}
|
102
|
+
else if (strVal.startsWith("0")) {
|
103
|
+
var newValue = strVal.replace(/^(0+)(?=((0|[1-9])\d*\.))/g, "");
|
104
|
+
onChange(newValue);
|
105
|
+
}
|
103
106
|
}, [value, onChange]);
|
104
107
|
var onOpenTooltip = useCallback(function () {
|
105
108
|
setTooltipOpen(true);
|