@react-aria/numberfield 3.9.0 → 3.10.0
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/import.mjs +89 -77
- package/dist/main.js +90 -77
- package/dist/main.js.map +1 -1
- package/dist/module.js +89 -77
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +12 -13
- package/src/useNumberField.ts +22 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/numberfield",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -22,17 +22,16 @@
|
|
|
22
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@react-aria/i18n": "^3.
|
|
26
|
-
"@react-aria/interactions": "^3.
|
|
27
|
-
"@react-aria/
|
|
28
|
-
"@react-aria/
|
|
29
|
-
"@react-aria/
|
|
30
|
-
"@react-
|
|
31
|
-
"@react-stately/numberfield": "^3.
|
|
32
|
-
"@react-types/button": "^3.9.
|
|
33
|
-
"@react-types/numberfield": "^3.
|
|
34
|
-
"@react-types/shared": "^3.
|
|
35
|
-
"@react-types/textfield": "^3.8.1",
|
|
25
|
+
"@react-aria/i18n": "^3.9.0",
|
|
26
|
+
"@react-aria/interactions": "^3.20.0",
|
|
27
|
+
"@react-aria/spinbutton": "^3.6.0",
|
|
28
|
+
"@react-aria/textfield": "^3.13.0",
|
|
29
|
+
"@react-aria/utils": "^3.22.0",
|
|
30
|
+
"@react-stately/form": "^3.0.0",
|
|
31
|
+
"@react-stately/numberfield": "^3.7.0",
|
|
32
|
+
"@react-types/button": "^3.9.1",
|
|
33
|
+
"@react-types/numberfield": "^3.7.0",
|
|
34
|
+
"@react-types/shared": "^3.22.0",
|
|
36
35
|
"@swc/helpers": "^0.5.0"
|
|
37
36
|
},
|
|
38
37
|
"peerDependencies": {
|
|
@@ -42,5 +41,5 @@
|
|
|
42
41
|
"publishConfig": {
|
|
43
42
|
"access": "public"
|
|
44
43
|
},
|
|
45
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "9ce2f674eab2cc8912800d3162dcf00a1ce94274"
|
|
46
45
|
}
|
package/src/useNumberField.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import {AriaButtonProps} from '@react-types/button';
|
|
14
14
|
import {AriaNumberFieldProps} from '@react-types/numberfield';
|
|
15
15
|
import {chain, filterDOMProps, isAndroid, isIOS, isIPhone, mergeProps, useFormReset, useId} from '@react-aria/utils';
|
|
16
|
-
import {DOMAttributes, GroupDOMAttributes, TextInputDOMProps} from '@react-types/shared';
|
|
16
|
+
import {DOMAttributes, GroupDOMAttributes, TextInputDOMProps, ValidationResult} from '@react-types/shared';
|
|
17
17
|
import {
|
|
18
18
|
InputHTMLAttributes,
|
|
19
19
|
LabelHTMLAttributes,
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
// @ts-ignore
|
|
26
26
|
import intlMessages from '../intl/*.json';
|
|
27
27
|
import {NumberFieldState} from '@react-stately/numberfield';
|
|
28
|
+
import {privateValidationStateProp} from '@react-stately/form';
|
|
28
29
|
import {useFocus, useFocusWithin, useScrollWheel} from '@react-aria/interactions';
|
|
29
30
|
import {useFormattedTextField} from '@react-aria/textfield';
|
|
30
31
|
import {
|
|
@@ -33,7 +34,7 @@ import {
|
|
|
33
34
|
} from '@react-aria/i18n';
|
|
34
35
|
import {useSpinButton} from '@react-aria/spinbutton';
|
|
35
36
|
|
|
36
|
-
export interface NumberFieldAria {
|
|
37
|
+
export interface NumberFieldAria extends ValidationResult {
|
|
37
38
|
/** Props for the label element. */
|
|
38
39
|
labelProps: LabelHTMLAttributes<HTMLLabelElement>,
|
|
39
40
|
/** Props for the group wrapper around the input and stepper buttons. */
|
|
@@ -65,8 +66,6 @@ export function useNumberField(props: AriaNumberFieldProps, state: NumberFieldSt
|
|
|
65
66
|
minValue,
|
|
66
67
|
maxValue,
|
|
67
68
|
autoFocus,
|
|
68
|
-
validationState,
|
|
69
|
-
isInvalid,
|
|
70
69
|
label,
|
|
71
70
|
formatOptions,
|
|
72
71
|
onBlur = () => {},
|
|
@@ -86,15 +85,15 @@ export function useNumberField(props: AriaNumberFieldProps, state: NumberFieldSt
|
|
|
86
85
|
decrementToMin,
|
|
87
86
|
numberValue,
|
|
88
87
|
inputValue,
|
|
89
|
-
commit
|
|
88
|
+
commit,
|
|
89
|
+
commitValidation
|
|
90
90
|
} = state;
|
|
91
91
|
|
|
92
92
|
const stringFormatter = useLocalizedStringFormatter(intlMessages);
|
|
93
93
|
|
|
94
94
|
let inputId = useId(id);
|
|
95
|
-
|
|
96
95
|
let {focusProps} = useFocus({
|
|
97
|
-
onBlur
|
|
96
|
+
onBlur() {
|
|
98
97
|
// Set input value to normalized valid value
|
|
99
98
|
commit();
|
|
100
99
|
}
|
|
@@ -185,9 +184,13 @@ export function useNumberField(props: AriaNumberFieldProps, state: NumberFieldSt
|
|
|
185
184
|
let onKeyDownEnter = useCallback((e) => {
|
|
186
185
|
if (e.key === 'Enter') {
|
|
187
186
|
commit();
|
|
187
|
+
commitValidation();
|
|
188
|
+
} else {
|
|
189
|
+
e.continuePropagation();
|
|
188
190
|
}
|
|
189
|
-
}, [commit]);
|
|
191
|
+
}, [commit, commitValidation]);
|
|
190
192
|
|
|
193
|
+
let {isInvalid, validationErrors, validationDetails} = state.displayValidation;
|
|
191
194
|
let {labelProps, inputProps: textFieldProps, descriptionProps, errorMessageProps} = useFormattedTextField({
|
|
192
195
|
...otherProps,
|
|
193
196
|
...domProps,
|
|
@@ -197,8 +200,8 @@ export function useNumberField(props: AriaNumberFieldProps, state: NumberFieldSt
|
|
|
197
200
|
isDisabled,
|
|
198
201
|
isReadOnly,
|
|
199
202
|
isRequired,
|
|
200
|
-
|
|
201
|
-
|
|
203
|
+
validate: undefined,
|
|
204
|
+
[privateValidationStateProp]: state,
|
|
202
205
|
value: inputValue,
|
|
203
206
|
defaultValue: undefined, // defaultValue already used to populate state.inputValue, unneeded here
|
|
204
207
|
autoComplete: 'off',
|
|
@@ -237,6 +240,10 @@ export function useNumberField(props: AriaNumberFieldProps, state: NumberFieldSt
|
|
|
237
240
|
}
|
|
238
241
|
);
|
|
239
242
|
|
|
243
|
+
if (props.validationBehavior === 'native') {
|
|
244
|
+
inputProps['aria-required'] = undefined;
|
|
245
|
+
}
|
|
246
|
+
|
|
240
247
|
let onButtonPressStart = (e) => {
|
|
241
248
|
// If focus is already on the input, keep it there so we don't hide the
|
|
242
249
|
// software keyboard when tapping the increment/decrement buttons.
|
|
@@ -302,13 +309,16 @@ export function useNumberField(props: AriaNumberFieldProps, state: NumberFieldSt
|
|
|
302
309
|
...focusWithinProps,
|
|
303
310
|
role: 'group',
|
|
304
311
|
'aria-disabled': isDisabled,
|
|
305
|
-
'aria-invalid': isInvalid
|
|
312
|
+
'aria-invalid': isInvalid ? 'true' : undefined
|
|
306
313
|
},
|
|
307
314
|
labelProps,
|
|
308
315
|
inputProps,
|
|
309
316
|
incrementButtonProps,
|
|
310
317
|
decrementButtonProps,
|
|
311
318
|
errorMessageProps,
|
|
312
|
-
descriptionProps
|
|
319
|
+
descriptionProps,
|
|
320
|
+
isInvalid,
|
|
321
|
+
validationErrors,
|
|
322
|
+
validationDetails
|
|
313
323
|
};
|
|
314
324
|
}
|