@react-aria/numberfield 3.0.0-nightly.2517 → 3.0.0-nightly.2531

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.
@@ -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,11 +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
188
  } else {
189
189
  e.continuePropagation();
190
190
  }
191
- }, [commit]);
191
+ }, [commit, commitValidation]);
192
192
 
193
+ let {isInvalid, validationErrors, validationDetails} = state.displayValidation;
193
194
  let {labelProps, inputProps: textFieldProps, descriptionProps, errorMessageProps} = useFormattedTextField({
194
195
  ...otherProps,
195
196
  ...domProps,
@@ -199,8 +200,8 @@ export function useNumberField(props: AriaNumberFieldProps, state: NumberFieldSt
199
200
  isDisabled,
200
201
  isReadOnly,
201
202
  isRequired,
202
- validationState,
203
- isInvalid,
203
+ validate: undefined,
204
+ [privateValidationStateProp]: state,
204
205
  value: inputValue,
205
206
  defaultValue: undefined, // defaultValue already used to populate state.inputValue, unneeded here
206
207
  autoComplete: 'off',
@@ -239,6 +240,10 @@ export function useNumberField(props: AriaNumberFieldProps, state: NumberFieldSt
239
240
  }
240
241
  );
241
242
 
243
+ if (props.validationBehavior === 'native') {
244
+ inputProps['aria-required'] = undefined;
245
+ }
246
+
242
247
  let onButtonPressStart = (e) => {
243
248
  // If focus is already on the input, keep it there so we don't hide the
244
249
  // software keyboard when tapping the increment/decrement buttons.
@@ -304,13 +309,16 @@ export function useNumberField(props: AriaNumberFieldProps, state: NumberFieldSt
304
309
  ...focusWithinProps,
305
310
  role: 'group',
306
311
  'aria-disabled': isDisabled,
307
- 'aria-invalid': isInvalid || validationState === 'invalid' ? 'true' : undefined
312
+ 'aria-invalid': isInvalid ? 'true' : undefined
308
313
  },
309
314
  labelProps,
310
315
  inputProps,
311
316
  incrementButtonProps,
312
317
  decrementButtonProps,
313
318
  errorMessageProps,
314
- descriptionProps
319
+ descriptionProps,
320
+ isInvalid,
321
+ validationErrors,
322
+ validationDetails
315
323
  };
316
324
  }