@react-stately/numberfield 3.9.2 → 3.9.3
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.
|
@@ -35,7 +35,7 @@ function $e18a693eeaf9c060$export$7f629e9dc1ecf37c(props) {
|
|
|
35
35
|
else defaultValue = (0, $gPCRT$reactstatelyutils.clamp)(defaultValue, minValue, maxValue);
|
|
36
36
|
}
|
|
37
37
|
let [numberValue, setNumberValue] = (0, $gPCRT$reactstatelyutils.useControlledState)(value, isNaN(defaultValue) ? NaN : defaultValue, onChange);
|
|
38
|
-
let [inputValue, setInputValue] = (0, $gPCRT$react.useState)(()=>isNaN(numberValue) ?
|
|
38
|
+
let [inputValue, setInputValue] = (0, $gPCRT$react.useState)(()=>isNaN(numberValue) ? '' : new (0, $gPCRT$internationalizednumber.NumberFormatter)(locale, formatOptions).format(numberValue));
|
|
39
39
|
let numberParser = (0, $gPCRT$react.useMemo)(()=>new (0, $gPCRT$internationalizednumber.NumberParser)(locale, formatOptions), [
|
|
40
40
|
locale,
|
|
41
41
|
formatOptions
|
|
@@ -55,7 +55,7 @@ function $e18a693eeaf9c060$export$7f629e9dc1ecf37c(props) {
|
|
|
55
55
|
let intlOptions = (0, $gPCRT$react.useMemo)(()=>formatter.resolvedOptions(), [
|
|
56
56
|
formatter
|
|
57
57
|
]);
|
|
58
|
-
let format = (0, $gPCRT$react.useCallback)((value)=>isNaN(value) || value === null ?
|
|
58
|
+
let format = (0, $gPCRT$react.useCallback)((value)=>isNaN(value) || value === null ? '' : formatter.format(value), [
|
|
59
59
|
formatter
|
|
60
60
|
]);
|
|
61
61
|
let validation = (0, $gPCRT$reactstatelyform.useFormValidationState)({
|
|
@@ -63,7 +63,7 @@ function $e18a693eeaf9c060$export$7f629e9dc1ecf37c(props) {
|
|
|
63
63
|
value: numberValue
|
|
64
64
|
});
|
|
65
65
|
let clampStep = step !== undefined && !isNaN(step) ? step : 1;
|
|
66
|
-
if (intlOptions.style ===
|
|
66
|
+
if (intlOptions.style === 'percent' && (step === undefined || isNaN(step))) clampStep = 0.01;
|
|
67
67
|
// Update the input value when the number value or format options change. This is done
|
|
68
68
|
// in a useEffect so that the controlled behavior is correct and we only update the
|
|
69
69
|
// textfield after prop changes.
|
|
@@ -84,7 +84,7 @@ function $e18a693eeaf9c060$export$7f629e9dc1ecf37c(props) {
|
|
|
84
84
|
// Set to empty state if input value is empty
|
|
85
85
|
if (!inputValue.length) {
|
|
86
86
|
setNumberValue(NaN);
|
|
87
|
-
setInputValue(value === undefined ?
|
|
87
|
+
setInputValue(value === undefined ? '' : format(numberValue));
|
|
88
88
|
return;
|
|
89
89
|
}
|
|
90
90
|
// if it failed to parse, then reset input to formatted version of current number
|
|
@@ -112,12 +112,12 @@ function $e18a693eeaf9c060$export$7f629e9dc1ecf37c(props) {
|
|
|
112
112
|
// otherwise, first snap the current value to the nearest step. if it moves in the direction
|
|
113
113
|
// we're going, use that value, otherwise add the step and snap that value.
|
|
114
114
|
let newValue = (0, $gPCRT$reactstatelyutils.snapValueToStep)(prev, minValue, maxValue, clampStep);
|
|
115
|
-
if (operation ===
|
|
115
|
+
if (operation === '+' && newValue > prev || operation === '-' && newValue < prev) return newValue;
|
|
116
116
|
return (0, $gPCRT$reactstatelyutils.snapValueToStep)($e18a693eeaf9c060$var$handleDecimalOperation(operation, prev, clampStep), minValue, maxValue, clampStep);
|
|
117
117
|
}
|
|
118
118
|
};
|
|
119
119
|
let increment = ()=>{
|
|
120
|
-
let newValue = safeNextStep(
|
|
120
|
+
let newValue = safeNextStep('+', minValue);
|
|
121
121
|
// if we've arrived at the same value that was previously in the state, the
|
|
122
122
|
// input value should be updated to match
|
|
123
123
|
// ex type 4, press increment, highlight the number in the input, type 4 again, press increment
|
|
@@ -127,7 +127,7 @@ function $e18a693eeaf9c060$export$7f629e9dc1ecf37c(props) {
|
|
|
127
127
|
validation.commitValidation();
|
|
128
128
|
};
|
|
129
129
|
let decrement = ()=>{
|
|
130
|
-
let newValue = safeNextStep(
|
|
130
|
+
let newValue = safeNextStep('-', maxValue);
|
|
131
131
|
if (newValue === numberValue) setInputValue(format(newValue));
|
|
132
132
|
setNumberValue(newValue);
|
|
133
133
|
validation.commitValidation();
|
|
@@ -144,7 +144,7 @@ function $e18a693eeaf9c060$export$7f629e9dc1ecf37c(props) {
|
|
|
144
144
|
validation.commitValidation();
|
|
145
145
|
}
|
|
146
146
|
};
|
|
147
|
-
let canIncrement = (0, $gPCRT$react.useMemo)(()=>!isDisabled && !isReadOnly && (isNaN(parsedValue) || maxValue === undefined || isNaN(maxValue) || (0, $gPCRT$reactstatelyutils.snapValueToStep)(parsedValue, minValue, maxValue, clampStep) > parsedValue || $e18a693eeaf9c060$var$handleDecimalOperation(
|
|
147
|
+
let canIncrement = (0, $gPCRT$react.useMemo)(()=>!isDisabled && !isReadOnly && (isNaN(parsedValue) || maxValue === undefined || isNaN(maxValue) || (0, $gPCRT$reactstatelyutils.snapValueToStep)(parsedValue, minValue, maxValue, clampStep) > parsedValue || $e18a693eeaf9c060$var$handleDecimalOperation('+', parsedValue, clampStep) <= maxValue), [
|
|
148
148
|
isDisabled,
|
|
149
149
|
isReadOnly,
|
|
150
150
|
minValue,
|
|
@@ -152,7 +152,7 @@ function $e18a693eeaf9c060$export$7f629e9dc1ecf37c(props) {
|
|
|
152
152
|
clampStep,
|
|
153
153
|
parsedValue
|
|
154
154
|
]);
|
|
155
|
-
let canDecrement = (0, $gPCRT$react.useMemo)(()=>!isDisabled && !isReadOnly && (isNaN(parsedValue) || minValue === undefined || isNaN(minValue) || (0, $gPCRT$reactstatelyutils.snapValueToStep)(parsedValue, minValue, maxValue, clampStep) < parsedValue || $e18a693eeaf9c060$var$handleDecimalOperation(
|
|
155
|
+
let canDecrement = (0, $gPCRT$react.useMemo)(()=>!isDisabled && !isReadOnly && (isNaN(parsedValue) || minValue === undefined || isNaN(minValue) || (0, $gPCRT$reactstatelyutils.snapValueToStep)(parsedValue, minValue, maxValue, clampStep) < parsedValue || $e18a693eeaf9c060$var$handleDecimalOperation('-', parsedValue, clampStep) >= minValue), [
|
|
156
156
|
isDisabled,
|
|
157
157
|
isReadOnly,
|
|
158
158
|
minValue,
|
|
@@ -180,11 +180,11 @@ function $e18a693eeaf9c060$export$7f629e9dc1ecf37c(props) {
|
|
|
180
180
|
};
|
|
181
181
|
}
|
|
182
182
|
function $e18a693eeaf9c060$var$handleDecimalOperation(operator, value1, value2) {
|
|
183
|
-
let result = operator ===
|
|
183
|
+
let result = operator === '+' ? value1 + value2 : value1 - value2;
|
|
184
184
|
// Check if we have decimals
|
|
185
185
|
if (value1 % 1 !== 0 || value2 % 1 !== 0) {
|
|
186
|
-
const value1Decimal = value1.toString().split(
|
|
187
|
-
const value2Decimal = value2.toString().split(
|
|
186
|
+
const value1Decimal = value1.toString().split('.');
|
|
187
|
+
const value2Decimal = value2.toString().split('.');
|
|
188
188
|
const value1DecimalLength = value1Decimal[1] && value1Decimal[1].length || 0;
|
|
189
189
|
const value2DecimalLength = value2Decimal[1] && value2Decimal[1].length || 0;
|
|
190
190
|
const multiplier = Math.pow(10, Math.max(value1DecimalLength, value2DecimalLength));
|
|
@@ -192,7 +192,7 @@ function $e18a693eeaf9c060$var$handleDecimalOperation(operator, value1, value2)
|
|
|
192
192
|
value1 = Math.round(value1 * multiplier);
|
|
193
193
|
value2 = Math.round(value2 * multiplier);
|
|
194
194
|
// Perform the operation on integers values to make sure we don't get a fancy decimal value
|
|
195
|
-
result = operator ===
|
|
195
|
+
result = operator === '+' ? value1 + value2 : value1 - value2;
|
|
196
196
|
// Transform the integer result back to decimal
|
|
197
197
|
result /= multiplier;
|
|
198
198
|
}
|
|
@@ -29,7 +29,7 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
29
29
|
else defaultValue = (0, $kNCPO$clamp)(defaultValue, minValue, maxValue);
|
|
30
30
|
}
|
|
31
31
|
let [numberValue, setNumberValue] = (0, $kNCPO$useControlledState)(value, isNaN(defaultValue) ? NaN : defaultValue, onChange);
|
|
32
|
-
let [inputValue, setInputValue] = (0, $kNCPO$useState)(()=>isNaN(numberValue) ?
|
|
32
|
+
let [inputValue, setInputValue] = (0, $kNCPO$useState)(()=>isNaN(numberValue) ? '' : new (0, $kNCPO$NumberFormatter)(locale, formatOptions).format(numberValue));
|
|
33
33
|
let numberParser = (0, $kNCPO$useMemo)(()=>new (0, $kNCPO$NumberParser)(locale, formatOptions), [
|
|
34
34
|
locale,
|
|
35
35
|
formatOptions
|
|
@@ -49,7 +49,7 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
49
49
|
let intlOptions = (0, $kNCPO$useMemo)(()=>formatter.resolvedOptions(), [
|
|
50
50
|
formatter
|
|
51
51
|
]);
|
|
52
|
-
let format = (0, $kNCPO$useCallback)((value)=>isNaN(value) || value === null ?
|
|
52
|
+
let format = (0, $kNCPO$useCallback)((value)=>isNaN(value) || value === null ? '' : formatter.format(value), [
|
|
53
53
|
formatter
|
|
54
54
|
]);
|
|
55
55
|
let validation = (0, $kNCPO$useFormValidationState)({
|
|
@@ -57,7 +57,7 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
57
57
|
value: numberValue
|
|
58
58
|
});
|
|
59
59
|
let clampStep = step !== undefined && !isNaN(step) ? step : 1;
|
|
60
|
-
if (intlOptions.style ===
|
|
60
|
+
if (intlOptions.style === 'percent' && (step === undefined || isNaN(step))) clampStep = 0.01;
|
|
61
61
|
// Update the input value when the number value or format options change. This is done
|
|
62
62
|
// in a useEffect so that the controlled behavior is correct and we only update the
|
|
63
63
|
// textfield after prop changes.
|
|
@@ -78,7 +78,7 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
78
78
|
// Set to empty state if input value is empty
|
|
79
79
|
if (!inputValue.length) {
|
|
80
80
|
setNumberValue(NaN);
|
|
81
|
-
setInputValue(value === undefined ?
|
|
81
|
+
setInputValue(value === undefined ? '' : format(numberValue));
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
84
|
// if it failed to parse, then reset input to formatted version of current number
|
|
@@ -106,12 +106,12 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
106
106
|
// otherwise, first snap the current value to the nearest step. if it moves in the direction
|
|
107
107
|
// we're going, use that value, otherwise add the step and snap that value.
|
|
108
108
|
let newValue = (0, $kNCPO$snapValueToStep)(prev, minValue, maxValue, clampStep);
|
|
109
|
-
if (operation ===
|
|
109
|
+
if (operation === '+' && newValue > prev || operation === '-' && newValue < prev) return newValue;
|
|
110
110
|
return (0, $kNCPO$snapValueToStep)($de67e98908f0c6ee$var$handleDecimalOperation(operation, prev, clampStep), minValue, maxValue, clampStep);
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
113
|
let increment = ()=>{
|
|
114
|
-
let newValue = safeNextStep(
|
|
114
|
+
let newValue = safeNextStep('+', minValue);
|
|
115
115
|
// if we've arrived at the same value that was previously in the state, the
|
|
116
116
|
// input value should be updated to match
|
|
117
117
|
// ex type 4, press increment, highlight the number in the input, type 4 again, press increment
|
|
@@ -121,7 +121,7 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
121
121
|
validation.commitValidation();
|
|
122
122
|
};
|
|
123
123
|
let decrement = ()=>{
|
|
124
|
-
let newValue = safeNextStep(
|
|
124
|
+
let newValue = safeNextStep('-', maxValue);
|
|
125
125
|
if (newValue === numberValue) setInputValue(format(newValue));
|
|
126
126
|
setNumberValue(newValue);
|
|
127
127
|
validation.commitValidation();
|
|
@@ -138,7 +138,7 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
138
138
|
validation.commitValidation();
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
|
-
let canIncrement = (0, $kNCPO$useMemo)(()=>!isDisabled && !isReadOnly && (isNaN(parsedValue) || maxValue === undefined || isNaN(maxValue) || (0, $kNCPO$snapValueToStep)(parsedValue, minValue, maxValue, clampStep) > parsedValue || $de67e98908f0c6ee$var$handleDecimalOperation(
|
|
141
|
+
let canIncrement = (0, $kNCPO$useMemo)(()=>!isDisabled && !isReadOnly && (isNaN(parsedValue) || maxValue === undefined || isNaN(maxValue) || (0, $kNCPO$snapValueToStep)(parsedValue, minValue, maxValue, clampStep) > parsedValue || $de67e98908f0c6ee$var$handleDecimalOperation('+', parsedValue, clampStep) <= maxValue), [
|
|
142
142
|
isDisabled,
|
|
143
143
|
isReadOnly,
|
|
144
144
|
minValue,
|
|
@@ -146,7 +146,7 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
146
146
|
clampStep,
|
|
147
147
|
parsedValue
|
|
148
148
|
]);
|
|
149
|
-
let canDecrement = (0, $kNCPO$useMemo)(()=>!isDisabled && !isReadOnly && (isNaN(parsedValue) || minValue === undefined || isNaN(minValue) || (0, $kNCPO$snapValueToStep)(parsedValue, minValue, maxValue, clampStep) < parsedValue || $de67e98908f0c6ee$var$handleDecimalOperation(
|
|
149
|
+
let canDecrement = (0, $kNCPO$useMemo)(()=>!isDisabled && !isReadOnly && (isNaN(parsedValue) || minValue === undefined || isNaN(minValue) || (0, $kNCPO$snapValueToStep)(parsedValue, minValue, maxValue, clampStep) < parsedValue || $de67e98908f0c6ee$var$handleDecimalOperation('-', parsedValue, clampStep) >= minValue), [
|
|
150
150
|
isDisabled,
|
|
151
151
|
isReadOnly,
|
|
152
152
|
minValue,
|
|
@@ -174,11 +174,11 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
176
|
function $de67e98908f0c6ee$var$handleDecimalOperation(operator, value1, value2) {
|
|
177
|
-
let result = operator ===
|
|
177
|
+
let result = operator === '+' ? value1 + value2 : value1 - value2;
|
|
178
178
|
// Check if we have decimals
|
|
179
179
|
if (value1 % 1 !== 0 || value2 % 1 !== 0) {
|
|
180
|
-
const value1Decimal = value1.toString().split(
|
|
181
|
-
const value2Decimal = value2.toString().split(
|
|
180
|
+
const value1Decimal = value1.toString().split('.');
|
|
181
|
+
const value2Decimal = value2.toString().split('.');
|
|
182
182
|
const value1DecimalLength = value1Decimal[1] && value1Decimal[1].length || 0;
|
|
183
183
|
const value2DecimalLength = value2Decimal[1] && value2Decimal[1].length || 0;
|
|
184
184
|
const multiplier = Math.pow(10, Math.max(value1DecimalLength, value2DecimalLength));
|
|
@@ -186,7 +186,7 @@ function $de67e98908f0c6ee$var$handleDecimalOperation(operator, value1, value2)
|
|
|
186
186
|
value1 = Math.round(value1 * multiplier);
|
|
187
187
|
value2 = Math.round(value2 * multiplier);
|
|
188
188
|
// Perform the operation on integers values to make sure we don't get a fancy decimal value
|
|
189
|
-
result = operator ===
|
|
189
|
+
result = operator === '+' ? value1 + value2 : value1 - value2;
|
|
190
190
|
// Transform the integer result back to decimal
|
|
191
191
|
result /= multiplier;
|
|
192
192
|
}
|
|
@@ -195,4 +195,4 @@ function $de67e98908f0c6ee$var$handleDecimalOperation(operator, value1, value2)
|
|
|
195
195
|
|
|
196
196
|
|
|
197
197
|
export {$de67e98908f0c6ee$export$7f629e9dc1ecf37c as useNumberFieldState};
|
|
198
|
-
//# sourceMappingURL=useNumberFieldState.
|
|
198
|
+
//# sourceMappingURL=useNumberFieldState.module.js.map
|
|
@@ -29,7 +29,7 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
29
29
|
else defaultValue = (0, $kNCPO$clamp)(defaultValue, minValue, maxValue);
|
|
30
30
|
}
|
|
31
31
|
let [numberValue, setNumberValue] = (0, $kNCPO$useControlledState)(value, isNaN(defaultValue) ? NaN : defaultValue, onChange);
|
|
32
|
-
let [inputValue, setInputValue] = (0, $kNCPO$useState)(()=>isNaN(numberValue) ?
|
|
32
|
+
let [inputValue, setInputValue] = (0, $kNCPO$useState)(()=>isNaN(numberValue) ? '' : new (0, $kNCPO$NumberFormatter)(locale, formatOptions).format(numberValue));
|
|
33
33
|
let numberParser = (0, $kNCPO$useMemo)(()=>new (0, $kNCPO$NumberParser)(locale, formatOptions), [
|
|
34
34
|
locale,
|
|
35
35
|
formatOptions
|
|
@@ -49,7 +49,7 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
49
49
|
let intlOptions = (0, $kNCPO$useMemo)(()=>formatter.resolvedOptions(), [
|
|
50
50
|
formatter
|
|
51
51
|
]);
|
|
52
|
-
let format = (0, $kNCPO$useCallback)((value)=>isNaN(value) || value === null ?
|
|
52
|
+
let format = (0, $kNCPO$useCallback)((value)=>isNaN(value) || value === null ? '' : formatter.format(value), [
|
|
53
53
|
formatter
|
|
54
54
|
]);
|
|
55
55
|
let validation = (0, $kNCPO$useFormValidationState)({
|
|
@@ -57,7 +57,7 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
57
57
|
value: numberValue
|
|
58
58
|
});
|
|
59
59
|
let clampStep = step !== undefined && !isNaN(step) ? step : 1;
|
|
60
|
-
if (intlOptions.style ===
|
|
60
|
+
if (intlOptions.style === 'percent' && (step === undefined || isNaN(step))) clampStep = 0.01;
|
|
61
61
|
// Update the input value when the number value or format options change. This is done
|
|
62
62
|
// in a useEffect so that the controlled behavior is correct and we only update the
|
|
63
63
|
// textfield after prop changes.
|
|
@@ -78,7 +78,7 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
78
78
|
// Set to empty state if input value is empty
|
|
79
79
|
if (!inputValue.length) {
|
|
80
80
|
setNumberValue(NaN);
|
|
81
|
-
setInputValue(value === undefined ?
|
|
81
|
+
setInputValue(value === undefined ? '' : format(numberValue));
|
|
82
82
|
return;
|
|
83
83
|
}
|
|
84
84
|
// if it failed to parse, then reset input to formatted version of current number
|
|
@@ -106,12 +106,12 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
106
106
|
// otherwise, first snap the current value to the nearest step. if it moves in the direction
|
|
107
107
|
// we're going, use that value, otherwise add the step and snap that value.
|
|
108
108
|
let newValue = (0, $kNCPO$snapValueToStep)(prev, minValue, maxValue, clampStep);
|
|
109
|
-
if (operation ===
|
|
109
|
+
if (operation === '+' && newValue > prev || operation === '-' && newValue < prev) return newValue;
|
|
110
110
|
return (0, $kNCPO$snapValueToStep)($de67e98908f0c6ee$var$handleDecimalOperation(operation, prev, clampStep), minValue, maxValue, clampStep);
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
113
|
let increment = ()=>{
|
|
114
|
-
let newValue = safeNextStep(
|
|
114
|
+
let newValue = safeNextStep('+', minValue);
|
|
115
115
|
// if we've arrived at the same value that was previously in the state, the
|
|
116
116
|
// input value should be updated to match
|
|
117
117
|
// ex type 4, press increment, highlight the number in the input, type 4 again, press increment
|
|
@@ -121,7 +121,7 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
121
121
|
validation.commitValidation();
|
|
122
122
|
};
|
|
123
123
|
let decrement = ()=>{
|
|
124
|
-
let newValue = safeNextStep(
|
|
124
|
+
let newValue = safeNextStep('-', maxValue);
|
|
125
125
|
if (newValue === numberValue) setInputValue(format(newValue));
|
|
126
126
|
setNumberValue(newValue);
|
|
127
127
|
validation.commitValidation();
|
|
@@ -138,7 +138,7 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
138
138
|
validation.commitValidation();
|
|
139
139
|
}
|
|
140
140
|
};
|
|
141
|
-
let canIncrement = (0, $kNCPO$useMemo)(()=>!isDisabled && !isReadOnly && (isNaN(parsedValue) || maxValue === undefined || isNaN(maxValue) || (0, $kNCPO$snapValueToStep)(parsedValue, minValue, maxValue, clampStep) > parsedValue || $de67e98908f0c6ee$var$handleDecimalOperation(
|
|
141
|
+
let canIncrement = (0, $kNCPO$useMemo)(()=>!isDisabled && !isReadOnly && (isNaN(parsedValue) || maxValue === undefined || isNaN(maxValue) || (0, $kNCPO$snapValueToStep)(parsedValue, minValue, maxValue, clampStep) > parsedValue || $de67e98908f0c6ee$var$handleDecimalOperation('+', parsedValue, clampStep) <= maxValue), [
|
|
142
142
|
isDisabled,
|
|
143
143
|
isReadOnly,
|
|
144
144
|
minValue,
|
|
@@ -146,7 +146,7 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
146
146
|
clampStep,
|
|
147
147
|
parsedValue
|
|
148
148
|
]);
|
|
149
|
-
let canDecrement = (0, $kNCPO$useMemo)(()=>!isDisabled && !isReadOnly && (isNaN(parsedValue) || minValue === undefined || isNaN(minValue) || (0, $kNCPO$snapValueToStep)(parsedValue, minValue, maxValue, clampStep) < parsedValue || $de67e98908f0c6ee$var$handleDecimalOperation(
|
|
149
|
+
let canDecrement = (0, $kNCPO$useMemo)(()=>!isDisabled && !isReadOnly && (isNaN(parsedValue) || minValue === undefined || isNaN(minValue) || (0, $kNCPO$snapValueToStep)(parsedValue, minValue, maxValue, clampStep) < parsedValue || $de67e98908f0c6ee$var$handleDecimalOperation('-', parsedValue, clampStep) >= minValue), [
|
|
150
150
|
isDisabled,
|
|
151
151
|
isReadOnly,
|
|
152
152
|
minValue,
|
|
@@ -174,11 +174,11 @@ function $de67e98908f0c6ee$export$7f629e9dc1ecf37c(props) {
|
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
176
|
function $de67e98908f0c6ee$var$handleDecimalOperation(operator, value1, value2) {
|
|
177
|
-
let result = operator ===
|
|
177
|
+
let result = operator === '+' ? value1 + value2 : value1 - value2;
|
|
178
178
|
// Check if we have decimals
|
|
179
179
|
if (value1 % 1 !== 0 || value2 % 1 !== 0) {
|
|
180
|
-
const value1Decimal = value1.toString().split(
|
|
181
|
-
const value2Decimal = value2.toString().split(
|
|
180
|
+
const value1Decimal = value1.toString().split('.');
|
|
181
|
+
const value2Decimal = value2.toString().split('.');
|
|
182
182
|
const value1DecimalLength = value1Decimal[1] && value1Decimal[1].length || 0;
|
|
183
183
|
const value2DecimalLength = value2Decimal[1] && value2Decimal[1].length || 0;
|
|
184
184
|
const multiplier = Math.pow(10, Math.max(value1DecimalLength, value2DecimalLength));
|
|
@@ -186,7 +186,7 @@ function $de67e98908f0c6ee$var$handleDecimalOperation(operator, value1, value2)
|
|
|
186
186
|
value1 = Math.round(value1 * multiplier);
|
|
187
187
|
value2 = Math.round(value2 * multiplier);
|
|
188
188
|
// Perform the operation on integers values to make sure we don't get a fancy decimal value
|
|
189
|
-
result = operator ===
|
|
189
|
+
result = operator === '+' ? value1 + value2 : value1 - value2;
|
|
190
190
|
// Transform the integer result back to decimal
|
|
191
191
|
result /= multiplier;
|
|
192
192
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/numberfield",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.3",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@internationalized/number": "^3.5.
|
|
26
|
-
"@react-stately/form": "^3.0.
|
|
27
|
-
"@react-stately/utils": "^3.10.
|
|
28
|
-
"@react-types/numberfield": "^3.8.
|
|
25
|
+
"@internationalized/number": "^3.5.3",
|
|
26
|
+
"@react-stately/form": "^3.0.3",
|
|
27
|
+
"@react-stately/utils": "^3.10.1",
|
|
28
|
+
"@react-types/numberfield": "^3.8.3",
|
|
29
29
|
"@swc/helpers": "^0.5.0"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "b77d7d594dff4dcfb5359bffbcfd18142b146433"
|
|
38
38
|
}
|