-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathuseNumberFieldRoot.ts
783 lines (679 loc) · 24.3 KB
/
useNumberFieldRoot.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
import * as React from 'react';
import type {
UseNumberFieldRootParameters,
UseNumberFieldRootReturnValue,
} from './NumberFieldRoot.types';
import { useScrub } from './useScrub';
import { formatNumber } from '../utils/format';
import { toValidatedNumber } from '../utils/validate';
import {
ARABIC_RE,
HAN_RE,
PERCENTAGES,
getNumberLocaleDetails,
parseNumber,
} from '../utils/parse';
import {
CHANGE_VALUE_TICK_DELAY,
DEFAULT_STEP,
MAX_POINTER_MOVES_AFTER_TOUCH,
SCROLLING_POINTER_MOVE_DISTANCE,
START_AUTO_CHANGE_DELAY,
TOUCH_TIMEOUT,
} from '../utils/constants';
import { isIOS } from '../../utils/detectBrowser';
import { mergeReactProps } from '../../utils/mergeReactProps';
import { ownerDocument, ownerWindow } from '../../utils/owner';
import { useControlled } from '../../utils/useControlled';
import { useEnhancedEffect } from '../../utils/useEnhancedEffect';
import { useEventCallback } from '../../utils/useEventCallback';
import { useForcedRerendering } from '../../utils/useForcedRerendering';
import { useId } from '../../utils/useId';
import { useLatestRef } from '../../utils/useLatestRef';
import { useFieldRootContext } from '../../Field/Root/FieldRootContext';
import { useFieldControlValidation } from '../../Field/Control/useFieldControlValidation';
import { useForkRef } from '../../utils/useForkRef';
/**
* The basic building block for creating custom number fields.
*
* Demos:
*
* - [Number Field](https://mui.com/base-ui/react-number-field/#hook)
*
* API:
*
* - [useNumberFieldRoot API](https://mui.com/base-ui/react-number-field/hooks-api/#use-number-field-root)
*/
export function useNumberFieldRoot(
params: UseNumberFieldRootParameters,
): UseNumberFieldRootReturnValue {
const {
id: idProp,
name,
min,
max,
smallStep = 0.1,
step,
largeStep = 10,
required = false,
disabled = false,
invalid = false,
readOnly = false,
autoFocus = false,
allowWheelScrub = false,
format,
value: externalValue,
onValueChange: onValueChangeProp = () => {},
defaultValue,
} = params;
const {
labelId,
setDisabled,
setControlId,
validateOnChange,
setTouched,
setDirty,
validityData,
setValidityData,
} = useFieldRootContext();
useEnhancedEffect(() => {
setDisabled(disabled);
}, [disabled, setDisabled]);
const {
getInputValidationProps,
getValidationProps,
inputRef: inputValidationRef,
commitValidation,
} = useFieldControlValidation();
const minWithDefault = min ?? Number.MIN_SAFE_INTEGER;
const maxWithDefault = max ?? Number.MAX_SAFE_INTEGER;
const minWithZeroDefault = min ?? 0;
const formatStyle = format?.style;
const id = useId(idProp);
useEnhancedEffect(() => {
setControlId(id);
return () => {
setControlId(undefined);
};
}, [id, setControlId]);
const forceRender = useForcedRerendering();
const formatOptionsRef = useLatestRef(format);
const onValueChange = useEventCallback(onValueChangeProp);
const inputRef = React.useRef<HTMLInputElement>(null);
const mergedRef = useForkRef(inputRef, inputValidationRef);
const startTickTimeoutRef = React.useRef(-1);
const tickIntervalRef = React.useRef(-1);
const intentionalTouchCheckTimeoutRef = React.useRef(-1);
const isPressedRef = React.useRef(false);
const isHoldingShiftRef = React.useRef(false);
const isHoldingAltRef = React.useRef(false);
const incrementDownCoordsRef = React.useRef({ x: 0, y: 0 });
const movesAfterTouchRef = React.useRef(0);
const allowInputSyncRef = React.useRef(true);
const unsubscribeFromGlobalContextMenuRef = React.useRef<() => void>(() => {});
const isTouchingButtonRef = React.useRef(false);
const hasTouchedInputRef = React.useRef(false);
const [valueUnwrapped, setValueUnwrapped] = useControlled<number | null>({
controlled: externalValue,
default: defaultValue,
name: 'NumberField',
state: 'value',
});
const value = valueUnwrapped ?? null;
const valueRef = useLatestRef(value);
useEnhancedEffect(() => {
if (validityData.initialValue === null && value !== validityData.initialValue) {
setValidityData((prev) => ({ ...prev, initialValue: value }));
}
}, [setValidityData, validityData.initialValue, value]);
// During SSR, the value is formatted on the server, whose locale may differ from the client's
// locale. This causes a hydration mismatch, which we manually suppress. This is preferable to
// rendering an empty input field and then updating it with the formatted value, as the user
// can still see the value prior to hydration, even if it's not formatted correctly.
const [inputValue, setInputValue] = React.useState(() => formatNumber(value, [], format));
const [inputMode, setInputMode] = React.useState<'numeric' | 'decimal' | 'text'>('numeric');
const isMin = value != null && value <= minWithDefault;
const isMax = value != null && value >= maxWithDefault;
const getAllowedNonNumericKeys = useEventCallback(() => {
const { decimal, group, currency } = getNumberLocaleDetails([], format);
const keys = Array.from(new Set(['.', ',', decimal, group]));
if (formatStyle === 'percent') {
keys.push(...PERCENTAGES);
}
if (formatStyle === 'currency' && currency) {
keys.push(currency);
}
if (minWithDefault < 0) {
keys.push('-');
}
return keys;
});
const getStepAmount = useEventCallback(() => {
if (isHoldingAltRef.current) {
return smallStep;
}
if (isHoldingShiftRef.current) {
return largeStep;
}
return step;
});
const setValue = useEventCallback((unvalidatedValue: number | null, event?: Event) => {
const validatedValue = toValidatedNumber(unvalidatedValue, {
step: getStepAmount(),
format: formatOptionsRef.current,
minWithDefault,
maxWithDefault,
minWithZeroDefault,
});
onValueChange?.(validatedValue, event);
setValueUnwrapped(validatedValue);
setDirty(validatedValue !== validityData.initialValue);
if (validateOnChange) {
commitValidation(validatedValue);
}
// We need to force a re-render, because while the value may be unchanged, the formatting may
// be different. This forces the `useEnhancedEffect` to run which acts as a single source of
// truth to sync the input value.
forceRender();
});
const incrementValue = useEventCallback(
(amount: number, dir: 1 | -1, currentValue?: number | null, event?: Event) => {
const prevValue = currentValue == null ? value : currentValue;
const nextValue =
typeof prevValue === 'number' ? prevValue + amount * dir : Math.max(0, min ?? 0);
setValue(nextValue, event);
},
);
const stopAutoChange = useEventCallback(() => {
window.clearTimeout(intentionalTouchCheckTimeoutRef.current);
window.clearTimeout(startTickTimeoutRef.current);
window.clearInterval(tickIntervalRef.current);
unsubscribeFromGlobalContextMenuRef.current();
movesAfterTouchRef.current = 0;
});
const startAutoChange = useEventCallback((isIncrement: boolean) => {
stopAutoChange();
if (!inputRef.current) {
return;
}
const win = ownerWindow(inputRef.current);
function handleContextMenu(event: Event) {
event.preventDefault();
}
// A global context menu is necessary to prevent the context menu from appearing when the touch
// is slightly outside of the element's hit area.
win.addEventListener('contextmenu', handleContextMenu);
unsubscribeFromGlobalContextMenuRef.current = () => {
win.removeEventListener('contextmenu', handleContextMenu);
};
win.addEventListener(
'pointerup',
() => {
isPressedRef.current = false;
stopAutoChange();
},
{ once: true },
);
function tick() {
const amount = getStepAmount() ?? DEFAULT_STEP;
incrementValue(amount, isIncrement ? 1 : -1);
}
tick();
startTickTimeoutRef.current = window.setTimeout(() => {
tickIntervalRef.current = window.setInterval(tick, CHANGE_VALUE_TICK_DELAY);
}, START_AUTO_CHANGE_DELAY);
});
// We need to update the input value when the external `value` prop changes. This ends up acting
// as a single source of truth to update the input value, bypassing the need to manually set it in
// each event handler internally in this hook.
// This is done inside a layout effect as an alternative to the technique to set state during
// render as we're accessing a ref, which must be inside an effect.
// https://react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
//
// ESLint is disabled because it needs to run even if the parsed value hasn't changed, since the
// value still can be formatted differently.
// eslint-disable-next-line react-hooks/exhaustive-deps
useEnhancedEffect(function syncFormattedInputValueOnValueChange() {
// This ensures the value is only updated on blur rather than every keystroke, but still
// allows the input value to be updated when the value is changed externally.
if (!allowInputSyncRef.current) {
return;
}
const nextInputValue = formatNumber(value, [], formatOptionsRef.current);
if (nextInputValue !== inputValue) {
setInputValue(nextInputValue);
}
});
useEnhancedEffect(
function setDynamicInputModeForIOS() {
if (!isIOS()) {
return;
}
// iOS numeric software keyboard doesn't have a minus key, so we need to use the default
// keyboard to let the user input a negative number.
let computedInputMode: typeof inputMode = 'text';
if (minWithDefault >= 0) {
// iOS numeric software keyboard doesn't have a decimal key for "numeric" input mode, but
// this is better than the "text" input if possible to use.
computedInputMode = 'decimal';
}
setInputMode(computedInputMode);
},
[minWithDefault, formatStyle],
);
React.useEffect(() => {
return () => stopAutoChange();
}, [stopAutoChange]);
React.useEffect(
function registerGlobalStepModifierKeyListeners() {
if (disabled || readOnly || !inputRef.current) {
return undefined;
}
function handleWindowKeyDown(event: KeyboardEvent) {
if (event.shiftKey) {
isHoldingShiftRef.current = true;
}
if (event.altKey) {
isHoldingAltRef.current = true;
}
}
function handleWindowKeyUp(event: KeyboardEvent) {
if (!event.shiftKey) {
isHoldingShiftRef.current = false;
}
if (!event.altKey) {
isHoldingAltRef.current = false;
}
}
function handleWindowBlur() {
// A keyup event may not be dispatched when the window loses focus.
isHoldingShiftRef.current = false;
isHoldingAltRef.current = false;
}
const win = ownerWindow(inputRef.current);
win.addEventListener('keydown', handleWindowKeyDown, true);
win.addEventListener('keyup', handleWindowKeyUp, true);
win.addEventListener('blur', handleWindowBlur);
return () => {
win.removeEventListener('keydown', handleWindowKeyDown, true);
win.removeEventListener('keyup', handleWindowKeyUp, true);
win.removeEventListener('blur', handleWindowBlur);
};
},
[disabled, readOnly],
);
// The `onWheel` prop can't be prevented, so we need to use a global event listener.
React.useEffect(
function registerElementWheelListener() {
const element = inputRef.current;
if (disabled || readOnly || !allowWheelScrub || !element) {
return undefined;
}
function handleWheel(event: WheelEvent) {
if (
// Allow pinch-zooming.
event.ctrlKey ||
ownerDocument(inputRef.current).activeElement !== inputRef.current
) {
return;
}
// Prevent the default behavior to avoid scrolling the page.
event.preventDefault();
const amount = getStepAmount() ?? DEFAULT_STEP;
incrementValue(amount, event.deltaY > 0 ? -1 : 1, undefined, event);
}
element.addEventListener('wheel', handleWheel);
return () => {
element.removeEventListener('wheel', handleWheel);
};
},
[allowWheelScrub, incrementValue, disabled, readOnly, largeStep, step, getStepAmount],
);
const getGroupProps: UseNumberFieldRootReturnValue['getGroupProps'] = React.useCallback(
(externalProps = {}) =>
mergeReactProps(externalProps, {
role: 'group',
}),
[],
);
const getCommonButtonProps = React.useCallback(
(isIncrement: boolean, externalProps = {}) =>
mergeReactProps<'button'>(externalProps, {
disabled: disabled || (isIncrement ? isMax : isMin),
type: 'button',
'aria-readonly': readOnly || undefined,
'aria-label': isIncrement ? 'Increase' : 'Decrease',
'aria-controls': id,
// Keyboard users shouldn't have access to the buttons, since they can use the input element
// to change the value. On the other hand, `aria-hidden` is not applied because touch screen
// readers should be able to use the buttons.
tabIndex: -1,
style: {
WebkitUserSelect: 'none',
userSelect: 'none',
},
onTouchStart() {
isTouchingButtonRef.current = true;
},
onTouchEnd() {
isTouchingButtonRef.current = false;
},
onClick(event) {
const isDisabled = disabled || readOnly || (isIncrement ? isMax : isMin);
if (
event.defaultPrevented ||
isDisabled ||
// If it's not a keyboard/virtual click, ignore.
event.detail !== 0
) {
return;
}
const amount = getStepAmount() ?? DEFAULT_STEP;
incrementValue(amount, isIncrement ? 1 : -1, undefined, event.nativeEvent);
},
onPointerDown(event) {
const isMainButton = !event.button || event.button === 0;
const isDisabled = disabled || (isIncrement ? isMax : isMin);
if (event.defaultPrevented || readOnly || !isMainButton || isDisabled) {
return;
}
isPressedRef.current = true;
incrementDownCoordsRef.current = { x: event.clientX, y: event.clientY };
// Note: "pen" is sometimes returned for mouse usage on Linux Chrome.
if (event.pointerType !== 'touch') {
event.preventDefault();
inputRef.current?.focus();
startAutoChange(isIncrement);
} else {
// We need to check if the pointerdown was intentional, and not the result of a scroll
// or pinch-zoom. In that case, we don't want to change the value.
intentionalTouchCheckTimeoutRef.current = window.setTimeout(() => {
const moves = movesAfterTouchRef.current;
movesAfterTouchRef.current = 0;
if (moves < MAX_POINTER_MOVES_AFTER_TOUCH) {
startAutoChange(isIncrement);
} else {
stopAutoChange();
}
}, TOUCH_TIMEOUT);
}
},
onPointerMove(event) {
const isDisabled = disabled || readOnly || (isIncrement ? isMax : isMin);
if (isDisabled || event.pointerType !== 'touch' || !isPressedRef.current) {
return;
}
movesAfterTouchRef.current += 1;
const { x, y } = incrementDownCoordsRef.current;
const dx = x - event.clientX;
const dy = y - event.clientY;
// An alternative to this technique is to detect when the NumberField's parent container
// has been scrolled
if (dx ** 2 + dy ** 2 > SCROLLING_POINTER_MOVE_DISTANCE ** 2) {
stopAutoChange();
}
},
onMouseEnter(event) {
const isDisabled = disabled || readOnly || (isIncrement ? isMax : isMin);
if (
event.defaultPrevented ||
isDisabled ||
!isPressedRef.current ||
isTouchingButtonRef.current
) {
return;
}
startAutoChange(isIncrement);
},
onMouseLeave() {
if (isTouchingButtonRef.current) {
return;
}
stopAutoChange();
},
onMouseUp() {
if (isTouchingButtonRef.current) {
return;
}
stopAutoChange();
},
}),
[
disabled,
readOnly,
isMax,
isMin,
id,
incrementValue,
startAutoChange,
stopAutoChange,
getStepAmount,
],
);
const getIncrementButtonProps: UseNumberFieldRootReturnValue['getIncrementButtonProps'] =
React.useCallback(
(externalProps) => getCommonButtonProps(true, externalProps),
[getCommonButtonProps],
);
const getDecrementButtonProps: UseNumberFieldRootReturnValue['getDecrementButtonProps'] =
React.useCallback(
(externalProps) => getCommonButtonProps(false, externalProps),
[getCommonButtonProps],
);
const getInputProps: UseNumberFieldRootReturnValue['getInputProps'] = React.useCallback(
(externalProps = {}) =>
mergeReactProps<'input'>(getInputValidationProps(getValidationProps(externalProps)), {
id,
required,
autoFocus,
name,
disabled,
readOnly,
inputMode,
value: inputValue,
ref: mergedRef,
type: 'text',
autoComplete: 'off',
autoCorrect: 'off',
spellCheck: 'false',
'aria-roledescription': 'Number field',
'aria-invalid': invalid || undefined,
'aria-labelledby': labelId,
// If the server's locale does not match the client's locale, the formatting may not match,
// causing a hydration mismatch.
suppressHydrationWarning: true,
onFocus(event) {
if (event.defaultPrevented || readOnly || disabled || hasTouchedInputRef.current) {
return;
}
hasTouchedInputRef.current = true;
// Browsers set selection at the start of the input field by default. We want to set it at
// the end for the first focus.
const target = event.currentTarget;
const length = target.value.length;
target.setSelectionRange(length, length);
},
onBlur(event) {
if (event.defaultPrevented || readOnly || disabled) {
return;
}
setTouched(true);
commitValidation(valueRef.current);
allowInputSyncRef.current = true;
if (inputValue.trim() === '') {
setValue(null);
return;
}
const parsedValue = parseNumber(inputValue, formatOptionsRef.current);
if (parsedValue !== null) {
setValue(parsedValue, event.nativeEvent);
}
},
onChange(event) {
// Workaround for https://github.com/facebook/react/issues/9023
if (event.nativeEvent.defaultPrevented) {
return;
}
allowInputSyncRef.current = false;
const targetValue = event.target.value;
if (targetValue.trim() === '') {
setInputValue(targetValue);
setValue(null, event.nativeEvent);
return;
}
if (event.isTrusted) {
setInputValue(targetValue);
return;
}
const parsedValue = parseNumber(targetValue, formatOptionsRef.current);
if (parsedValue !== null) {
setInputValue(targetValue);
setValue(parsedValue, event.nativeEvent);
}
},
onKeyDown(event) {
if (event.defaultPrevented || readOnly || disabled) {
return;
}
const nativeEvent = event.nativeEvent;
allowInputSyncRef.current = true;
const allowedNonNumericKeys = getAllowedNonNumericKeys();
let isAllowedNonNumericKey = allowedNonNumericKeys.includes(event.key);
const { decimal, currency, percentSign } = getNumberLocaleDetails(
[],
formatOptionsRef.current,
);
const selectionStart = event.currentTarget.selectionStart;
const selectionEnd = event.currentTarget.selectionEnd;
const isAllSelected = selectionStart === 0 && selectionEnd === inputValue.length;
// Allow the minus key only if there isn't already a plus or minus sign, or if all the text
// is selected, or if only the minus sign is highlighted.
if (event.key === '-' && allowedNonNumericKeys.includes('-')) {
const isMinusHighlighted =
selectionStart === 0 && selectionEnd === 1 && inputValue[0] === '-';
isAllowedNonNumericKey =
!inputValue.includes('-') || isAllSelected || isMinusHighlighted;
}
// Only allow one of each symbol.
[decimal, currency, percentSign].forEach((symbol) => {
if (event.key === symbol) {
const symbolIndex = inputValue.indexOf(symbol);
const isSymbolHighlighted =
selectionStart === symbolIndex && selectionEnd === symbolIndex + 1;
isAllowedNonNumericKey =
!inputValue.includes(symbol) || isAllSelected || isSymbolHighlighted;
}
});
const isLatinNumeral = /^[0-9]$/.test(event.key);
const isArabicNumeral = ARABIC_RE.test(event.key);
const isHanNumeral = HAN_RE.test(event.key);
const isNavigateKey = [
'Backspace',
'Delete',
'ArrowLeft',
'ArrowRight',
'Tab',
'Enter',
].includes(event.key);
if (
// Allow composition events (e.g., pinyin)
nativeEvent.isComposing ||
event.altKey ||
event.ctrlKey ||
event.metaKey ||
isAllowedNonNumericKey ||
isLatinNumeral ||
isArabicNumeral ||
isHanNumeral ||
isNavigateKey
) {
return;
}
// We need to commit the number at this point if the input hasn't been blurred.
const parsedValue = parseNumber(inputValue, formatOptionsRef.current);
const amount = getStepAmount() ?? DEFAULT_STEP;
// Prevent insertion of text or caret from moving.
event.preventDefault();
if (event.key === 'ArrowUp') {
incrementValue(amount, 1, parsedValue, nativeEvent);
} else if (event.key === 'ArrowDown') {
incrementValue(amount, -1, parsedValue, nativeEvent);
} else if (event.key === 'Home' && min != null) {
setValue(min, nativeEvent);
} else if (event.key === 'End' && max != null) {
setValue(max, nativeEvent);
}
},
onPaste(event) {
if (event.defaultPrevented || readOnly || disabled) {
return;
}
// Prevent `onChange` from being called.
event.preventDefault();
const clipboardData = event.clipboardData || window.Clipboard;
const pastedData = clipboardData.getData('text/plain');
const parsedValue = parseNumber(pastedData, formatOptionsRef.current);
if (parsedValue !== null) {
allowInputSyncRef.current = false;
setValue(parsedValue, event.nativeEvent);
setInputValue(pastedData);
}
},
}),
[
getInputValidationProps,
getValidationProps,
id,
required,
autoFocus,
name,
disabled,
readOnly,
inputMode,
inputValue,
mergedRef,
invalid,
labelId,
setTouched,
formatOptionsRef,
commitValidation,
valueRef,
setValue,
getAllowedNonNumericKeys,
getStepAmount,
min,
max,
incrementValue,
],
);
const scrub = useScrub({
disabled,
readOnly,
value,
inputRef,
incrementValue,
getStepAmount,
});
return React.useMemo(
() => ({
getGroupProps,
getInputProps,
getIncrementButtonProps,
getDecrementButtonProps,
inputRef: mergedRef,
inputValue,
value,
...scrub,
}),
[
getGroupProps,
getInputProps,
getIncrementButtonProps,
getDecrementButtonProps,
mergedRef,
inputValue,
value,
scrub,
],
);
}