MCPcopy
hub / github.com/adobe/react-spectrum / useSpinButton

Function useSpinButton

packages/react-aria/src/spinbutton/useSpinButton.ts:42–323  ·  view source on GitHub ↗
(props: SpinButtonProps)

Source from the content-addressed store, hash-verified

40}
41
42export function useSpinButton(props: SpinButtonProps): SpinbuttonAria {
43 const _async = useRef<number>(undefined);
44 let {
45 value,
46 textValue,
47 minValue,
48 maxValue,
49 isDisabled,
50 isReadOnly,
51 isRequired,
52 onIncrement,
53 onIncrementPage,
54 onDecrement,
55 onDecrementPage,
56 onDecrementToMin,
57 onIncrementToMax
58 } = props;
59 const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/spinbutton');
60
61 let isSpinning = useRef(false);
62 const clearAsync = useCallback(() => {
63 clearTimeout(_async.current);
64 isSpinning.current = false;
65 }, []);
66 const clearAsyncEvent = useEffectEvent(() => {
67 clearAsync();
68 });
69
70 useEffect(() => {
71 return () => clearAsyncEvent();
72 }, []);
73
74 let onKeyDown = e => {
75 if (
76 e.ctrlKey ||
77 e.metaKey ||
78 e.shiftKey ||
79 e.altKey ||
80 isReadOnly ||
81 e.nativeEvent.isComposing
82 ) {
83 return;
84 }
85
86 switch (e.key) {
87 case 'PageUp':
88 if (onIncrementPage) {
89 e.preventDefault();
90 onIncrementPage?.();
91 break;
92 }
93 // fallthrough!
94 case 'ArrowUp':
95 case 'Up':
96 if (onIncrement) {
97 e.preventDefault();
98 onIncrement?.();
99 }

Callers 4

ExampleFunction · 0.90
useNumberFieldFunction · 0.90
useColorFieldFunction · 0.90
useDateSegmentFunction · 0.90

Calls 6

useEffectEventFunction · 0.90
clearAnnouncerFunction · 0.90
announceFunction · 0.90
useGlobalListenersFunction · 0.90
formatMethod · 0.45

Tested by 1

ExampleFunction · 0.72