MCPcopy Create free account
hub / github.com/adobe/react-spectrum / useSpinButton

Function useSpinButton

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

Source from the content-addressed store, hash-verified

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

Callers 4

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

Calls 7

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

Tested by 1

ExampleFunction · 0.72