@react-aria/spinbutton 3.6.3 → 3.6.4

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.
Files changed (50) hide show
  1. package/dist/ar-AE.mjs +1 -1
  2. package/dist/bg-BG.mjs +1 -1
  3. package/dist/cs-CZ.mjs +1 -1
  4. package/dist/da-DK.mjs +1 -1
  5. package/dist/de-DE.mjs +1 -1
  6. package/dist/el-GR.mjs +1 -1
  7. package/dist/en-US.mjs +1 -1
  8. package/dist/es-ES.mjs +1 -1
  9. package/dist/et-EE.mjs +1 -1
  10. package/dist/fi-FI.mjs +1 -1
  11. package/dist/fr-FR.mjs +1 -1
  12. package/dist/he-IL.mjs +1 -1
  13. package/dist/hr-HR.mjs +1 -1
  14. package/dist/hu-HU.mjs +1 -1
  15. package/dist/import.mjs +1 -264
  16. package/dist/intlStrings.main.js +108 -0
  17. package/dist/intlStrings.main.js.map +1 -0
  18. package/dist/intlStrings.mjs +110 -0
  19. package/dist/intlStrings.module.js +110 -0
  20. package/dist/intlStrings.module.js.map +1 -0
  21. package/dist/it-IT.mjs +1 -1
  22. package/dist/ja-JP.mjs +1 -1
  23. package/dist/ko-KR.mjs +1 -1
  24. package/dist/lt-LT.mjs +1 -1
  25. package/dist/lv-LV.mjs +1 -1
  26. package/dist/main.js +2 -265
  27. package/dist/main.js.map +1 -1
  28. package/dist/module.js +1 -264
  29. package/dist/module.js.map +1 -1
  30. package/dist/nb-NO.mjs +1 -1
  31. package/dist/nl-NL.mjs +1 -1
  32. package/dist/pl-PL.mjs +1 -1
  33. package/dist/pt-BR.mjs +1 -1
  34. package/dist/pt-PT.mjs +1 -1
  35. package/dist/ro-RO.mjs +1 -1
  36. package/dist/ru-RU.mjs +1 -1
  37. package/dist/sk-SK.mjs +1 -1
  38. package/dist/sl-SI.mjs +1 -1
  39. package/dist/sr-SP.mjs +1 -1
  40. package/dist/sv-SE.mjs +1 -1
  41. package/dist/tr-TR.mjs +1 -1
  42. package/dist/uk-UA.mjs +1 -1
  43. package/dist/useSpinButton.main.js +168 -0
  44. package/dist/useSpinButton.main.js.map +1 -0
  45. package/dist/useSpinButton.mjs +163 -0
  46. package/dist/useSpinButton.module.js +163 -0
  47. package/dist/useSpinButton.module.js.map +1 -0
  48. package/dist/zh-CN.mjs +1 -1
  49. package/dist/zh-TW.mjs +1 -1
  50. package/package.json +7 -7
@@ -0,0 +1,163 @@
1
+ import $5rwhf$intlStringsmodulejs from "./intlStrings.mjs";
2
+ import {clearAnnouncer as $5rwhf$clearAnnouncer, announce as $5rwhf$announce} from "@react-aria/live-announcer";
3
+ import {useRef as $5rwhf$useRef, useEffect as $5rwhf$useEffect} from "react";
4
+ import {useEffectEvent as $5rwhf$useEffectEvent, useGlobalListeners as $5rwhf$useGlobalListeners} from "@react-aria/utils";
5
+ import {useLocalizedStringFormatter as $5rwhf$useLocalizedStringFormatter} from "@react-aria/i18n";
6
+
7
+
8
+ function $parcel$interopDefault(a) {
9
+ return a && a.__esModule ? a.default : a;
10
+ }
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+
25
+
26
+ function $d2e8511e6f209edf$export$e908e06f4b8e3402(props) {
27
+ const _async = (0, $5rwhf$useRef)();
28
+ let { value: value, textValue: textValue, minValue: minValue, maxValue: maxValue, isDisabled: isDisabled, isReadOnly: isReadOnly, isRequired: isRequired, onIncrement: onIncrement, onIncrementPage: onIncrementPage, onDecrement: onDecrement, onDecrementPage: onDecrementPage, onDecrementToMin: onDecrementToMin, onIncrementToMax: onIncrementToMax } = props;
29
+ const stringFormatter = (0, $5rwhf$useLocalizedStringFormatter)((0, ($parcel$interopDefault($5rwhf$intlStringsmodulejs))), "@react-aria/spinbutton");
30
+ const clearAsync = ()=>clearTimeout(_async.current);
31
+ // eslint-disable-next-line arrow-body-style
32
+ (0, $5rwhf$useEffect)(()=>{
33
+ return ()=>clearAsync();
34
+ }, []);
35
+ let onKeyDown = (e)=>{
36
+ if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || isReadOnly) return;
37
+ switch(e.key){
38
+ case "PageUp":
39
+ if (onIncrementPage) {
40
+ e.preventDefault();
41
+ onIncrementPage === null || onIncrementPage === void 0 ? void 0 : onIncrementPage();
42
+ break;
43
+ }
44
+ // fallthrough!
45
+ case "ArrowUp":
46
+ case "Up":
47
+ if (onIncrement) {
48
+ e.preventDefault();
49
+ onIncrement === null || onIncrement === void 0 ? void 0 : onIncrement();
50
+ }
51
+ break;
52
+ case "PageDown":
53
+ if (onDecrementPage) {
54
+ e.preventDefault();
55
+ onDecrementPage === null || onDecrementPage === void 0 ? void 0 : onDecrementPage();
56
+ break;
57
+ }
58
+ // fallthrough
59
+ case "ArrowDown":
60
+ case "Down":
61
+ if (onDecrement) {
62
+ e.preventDefault();
63
+ onDecrement === null || onDecrement === void 0 ? void 0 : onDecrement();
64
+ }
65
+ break;
66
+ case "Home":
67
+ if (onDecrementToMin) {
68
+ e.preventDefault();
69
+ onDecrementToMin === null || onDecrementToMin === void 0 ? void 0 : onDecrementToMin();
70
+ }
71
+ break;
72
+ case "End":
73
+ if (onIncrementToMax) {
74
+ e.preventDefault();
75
+ onIncrementToMax === null || onIncrementToMax === void 0 ? void 0 : onIncrementToMax();
76
+ }
77
+ break;
78
+ }
79
+ };
80
+ let isFocused = (0, $5rwhf$useRef)(false);
81
+ let onFocus = ()=>{
82
+ isFocused.current = true;
83
+ };
84
+ let onBlur = ()=>{
85
+ isFocused.current = false;
86
+ };
87
+ // Replace Unicode hyphen-minus (U+002D) with minus sign (U+2212).
88
+ // This ensures that macOS VoiceOver announces it as "minus" even with other characters between the minus sign
89
+ // and the number (e.g. currency symbol). Otherwise it announces nothing because it assumes the character is a hyphen.
90
+ // In addition, replace the empty string with the word "Empty" so that iOS VoiceOver does not read "50%" for an empty field.
91
+ let ariaTextValue = textValue === "" ? stringFormatter.format("Empty") : (textValue || `${value}`).replace("-", "\u2212");
92
+ (0, $5rwhf$useEffect)(()=>{
93
+ if (isFocused.current) {
94
+ (0, $5rwhf$clearAnnouncer)("assertive");
95
+ (0, $5rwhf$announce)(ariaTextValue, "assertive");
96
+ }
97
+ }, [
98
+ ariaTextValue
99
+ ]);
100
+ const onIncrementPressStart = (0, $5rwhf$useEffectEvent)((initialStepDelay)=>{
101
+ clearAsync();
102
+ onIncrement === null || onIncrement === void 0 ? void 0 : onIncrement();
103
+ // Start spinning after initial delay
104
+ _async.current = window.setTimeout(()=>{
105
+ if (maxValue === undefined || isNaN(maxValue) || value === undefined || isNaN(value) || value < maxValue) onIncrementPressStart(60);
106
+ }, initialStepDelay);
107
+ });
108
+ const onDecrementPressStart = (0, $5rwhf$useEffectEvent)((initialStepDelay)=>{
109
+ clearAsync();
110
+ onDecrement === null || onDecrement === void 0 ? void 0 : onDecrement();
111
+ // Start spinning after initial delay
112
+ _async.current = window.setTimeout(()=>{
113
+ if (minValue === undefined || isNaN(minValue) || value === undefined || isNaN(value) || value > minValue) onDecrementPressStart(60);
114
+ }, initialStepDelay);
115
+ });
116
+ let cancelContextMenu = (e)=>{
117
+ e.preventDefault();
118
+ };
119
+ let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $5rwhf$useGlobalListeners)();
120
+ return {
121
+ spinButtonProps: {
122
+ role: "spinbutton",
123
+ "aria-valuenow": value !== undefined && !isNaN(value) ? value : undefined,
124
+ "aria-valuetext": ariaTextValue,
125
+ "aria-valuemin": minValue,
126
+ "aria-valuemax": maxValue,
127
+ "aria-disabled": isDisabled || undefined,
128
+ "aria-readonly": isReadOnly || undefined,
129
+ "aria-required": isRequired || undefined,
130
+ onKeyDown: onKeyDown,
131
+ onFocus: onFocus,
132
+ onBlur: onBlur
133
+ },
134
+ incrementButtonProps: {
135
+ onPressStart: ()=>{
136
+ onIncrementPressStart(400);
137
+ addGlobalListener(window, "contextmenu", cancelContextMenu);
138
+ },
139
+ onPressEnd: ()=>{
140
+ clearAsync();
141
+ removeAllGlobalListeners();
142
+ },
143
+ onFocus: onFocus,
144
+ onBlur: onBlur
145
+ },
146
+ decrementButtonProps: {
147
+ onPressStart: ()=>{
148
+ onDecrementPressStart(400);
149
+ addGlobalListener(window, "contextmenu", cancelContextMenu);
150
+ },
151
+ onPressEnd: ()=>{
152
+ clearAsync();
153
+ removeAllGlobalListeners();
154
+ },
155
+ onFocus: onFocus,
156
+ onBlur: onBlur
157
+ }
158
+ };
159
+ }
160
+
161
+
162
+ export {$d2e8511e6f209edf$export$e908e06f4b8e3402 as useSpinButton};
163
+ //# sourceMappingURL=useSpinButton.mjs.map
@@ -0,0 +1,163 @@
1
+ import $5rwhf$intlStringsmodulejs from "./intlStrings.module.js";
2
+ import {clearAnnouncer as $5rwhf$clearAnnouncer, announce as $5rwhf$announce} from "@react-aria/live-announcer";
3
+ import {useRef as $5rwhf$useRef, useEffect as $5rwhf$useEffect} from "react";
4
+ import {useEffectEvent as $5rwhf$useEffectEvent, useGlobalListeners as $5rwhf$useGlobalListeners} from "@react-aria/utils";
5
+ import {useLocalizedStringFormatter as $5rwhf$useLocalizedStringFormatter} from "@react-aria/i18n";
6
+
7
+
8
+ function $parcel$interopDefault(a) {
9
+ return a && a.__esModule ? a.default : a;
10
+ }
11
+ /*
12
+ * Copyright 2020 Adobe. All rights reserved.
13
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License. You may obtain a copy
15
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
16
+ *
17
+ * Unless required by applicable law or agreed to in writing, software distributed under
18
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
19
+ * OF ANY KIND, either express or implied. See the License for the specific language
20
+ * governing permissions and limitations under the License.
21
+ */
22
+
23
+
24
+
25
+
26
+ function $d2e8511e6f209edf$export$e908e06f4b8e3402(props) {
27
+ const _async = (0, $5rwhf$useRef)();
28
+ let { value: value, textValue: textValue, minValue: minValue, maxValue: maxValue, isDisabled: isDisabled, isReadOnly: isReadOnly, isRequired: isRequired, onIncrement: onIncrement, onIncrementPage: onIncrementPage, onDecrement: onDecrement, onDecrementPage: onDecrementPage, onDecrementToMin: onDecrementToMin, onIncrementToMax: onIncrementToMax } = props;
29
+ const stringFormatter = (0, $5rwhf$useLocalizedStringFormatter)((0, ($parcel$interopDefault($5rwhf$intlStringsmodulejs))), "@react-aria/spinbutton");
30
+ const clearAsync = ()=>clearTimeout(_async.current);
31
+ // eslint-disable-next-line arrow-body-style
32
+ (0, $5rwhf$useEffect)(()=>{
33
+ return ()=>clearAsync();
34
+ }, []);
35
+ let onKeyDown = (e)=>{
36
+ if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || isReadOnly) return;
37
+ switch(e.key){
38
+ case "PageUp":
39
+ if (onIncrementPage) {
40
+ e.preventDefault();
41
+ onIncrementPage === null || onIncrementPage === void 0 ? void 0 : onIncrementPage();
42
+ break;
43
+ }
44
+ // fallthrough!
45
+ case "ArrowUp":
46
+ case "Up":
47
+ if (onIncrement) {
48
+ e.preventDefault();
49
+ onIncrement === null || onIncrement === void 0 ? void 0 : onIncrement();
50
+ }
51
+ break;
52
+ case "PageDown":
53
+ if (onDecrementPage) {
54
+ e.preventDefault();
55
+ onDecrementPage === null || onDecrementPage === void 0 ? void 0 : onDecrementPage();
56
+ break;
57
+ }
58
+ // fallthrough
59
+ case "ArrowDown":
60
+ case "Down":
61
+ if (onDecrement) {
62
+ e.preventDefault();
63
+ onDecrement === null || onDecrement === void 0 ? void 0 : onDecrement();
64
+ }
65
+ break;
66
+ case "Home":
67
+ if (onDecrementToMin) {
68
+ e.preventDefault();
69
+ onDecrementToMin === null || onDecrementToMin === void 0 ? void 0 : onDecrementToMin();
70
+ }
71
+ break;
72
+ case "End":
73
+ if (onIncrementToMax) {
74
+ e.preventDefault();
75
+ onIncrementToMax === null || onIncrementToMax === void 0 ? void 0 : onIncrementToMax();
76
+ }
77
+ break;
78
+ }
79
+ };
80
+ let isFocused = (0, $5rwhf$useRef)(false);
81
+ let onFocus = ()=>{
82
+ isFocused.current = true;
83
+ };
84
+ let onBlur = ()=>{
85
+ isFocused.current = false;
86
+ };
87
+ // Replace Unicode hyphen-minus (U+002D) with minus sign (U+2212).
88
+ // This ensures that macOS VoiceOver announces it as "minus" even with other characters between the minus sign
89
+ // and the number (e.g. currency symbol). Otherwise it announces nothing because it assumes the character is a hyphen.
90
+ // In addition, replace the empty string with the word "Empty" so that iOS VoiceOver does not read "50%" for an empty field.
91
+ let ariaTextValue = textValue === "" ? stringFormatter.format("Empty") : (textValue || `${value}`).replace("-", "\u2212");
92
+ (0, $5rwhf$useEffect)(()=>{
93
+ if (isFocused.current) {
94
+ (0, $5rwhf$clearAnnouncer)("assertive");
95
+ (0, $5rwhf$announce)(ariaTextValue, "assertive");
96
+ }
97
+ }, [
98
+ ariaTextValue
99
+ ]);
100
+ const onIncrementPressStart = (0, $5rwhf$useEffectEvent)((initialStepDelay)=>{
101
+ clearAsync();
102
+ onIncrement === null || onIncrement === void 0 ? void 0 : onIncrement();
103
+ // Start spinning after initial delay
104
+ _async.current = window.setTimeout(()=>{
105
+ if (maxValue === undefined || isNaN(maxValue) || value === undefined || isNaN(value) || value < maxValue) onIncrementPressStart(60);
106
+ }, initialStepDelay);
107
+ });
108
+ const onDecrementPressStart = (0, $5rwhf$useEffectEvent)((initialStepDelay)=>{
109
+ clearAsync();
110
+ onDecrement === null || onDecrement === void 0 ? void 0 : onDecrement();
111
+ // Start spinning after initial delay
112
+ _async.current = window.setTimeout(()=>{
113
+ if (minValue === undefined || isNaN(minValue) || value === undefined || isNaN(value) || value > minValue) onDecrementPressStart(60);
114
+ }, initialStepDelay);
115
+ });
116
+ let cancelContextMenu = (e)=>{
117
+ e.preventDefault();
118
+ };
119
+ let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $5rwhf$useGlobalListeners)();
120
+ return {
121
+ spinButtonProps: {
122
+ role: "spinbutton",
123
+ "aria-valuenow": value !== undefined && !isNaN(value) ? value : undefined,
124
+ "aria-valuetext": ariaTextValue,
125
+ "aria-valuemin": minValue,
126
+ "aria-valuemax": maxValue,
127
+ "aria-disabled": isDisabled || undefined,
128
+ "aria-readonly": isReadOnly || undefined,
129
+ "aria-required": isRequired || undefined,
130
+ onKeyDown: onKeyDown,
131
+ onFocus: onFocus,
132
+ onBlur: onBlur
133
+ },
134
+ incrementButtonProps: {
135
+ onPressStart: ()=>{
136
+ onIncrementPressStart(400);
137
+ addGlobalListener(window, "contextmenu", cancelContextMenu);
138
+ },
139
+ onPressEnd: ()=>{
140
+ clearAsync();
141
+ removeAllGlobalListeners();
142
+ },
143
+ onFocus: onFocus,
144
+ onBlur: onBlur
145
+ },
146
+ decrementButtonProps: {
147
+ onPressStart: ()=>{
148
+ onDecrementPressStart(400);
149
+ addGlobalListener(window, "contextmenu", cancelContextMenu);
150
+ },
151
+ onPressEnd: ()=>{
152
+ clearAsync();
153
+ removeAllGlobalListeners();
154
+ },
155
+ onFocus: onFocus,
156
+ onBlur: onBlur
157
+ }
158
+ };
159
+ }
160
+
161
+
162
+ export {$d2e8511e6f209edf$export$e908e06f4b8e3402 as useSpinButton};
163
+ //# sourceMappingURL=useSpinButton.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AA4BM,SAAS,0CACd,KAAsB;IAEtB,MAAM,SAAS,CAAA,GAAA,aAAK;IACpB,IAAI,SACF,KAAK,aACL,SAAS,YACT,QAAQ,YACR,QAAQ,cACR,UAAU,cACV,UAA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B,kBAAkB,QAAQ,eAAe;YAC3C;YACA,YAAY;gBACV;gBACA;YACF;qBACA;oBACA;QACF;IACF;AACF","sources":["packages/@react-aria/spinbutton/src/useSpinButton.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {announce, clearAnnouncer} from '@react-aria/live-announcer';\nimport {AriaButtonProps} from '@react-types/button';\nimport {DOMAttributes, InputBase, RangeInputBase, Validation, ValueBase} from '@react-types/shared';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {useEffect, useRef} from 'react';\nimport {useEffectEvent, useGlobalListeners} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\n\nexport interface SpinButtonProps extends InputBase, Validation<number>, ValueBase<number>, RangeInputBase<number> {\n textValue?: string,\n onIncrement?: () => void,\n onIncrementPage?: () => void,\n onDecrement?: () => void,\n onDecrementPage?: () => void,\n onDecrementToMin?: () => void,\n onIncrementToMax?: () => void\n}\n\nexport interface SpinbuttonAria {\n spinButtonProps: DOMAttributes,\n incrementButtonProps: AriaButtonProps,\n decrementButtonProps: AriaButtonProps\n}\n\nexport function useSpinButton(\n props: SpinButtonProps\n): SpinbuttonAria {\n const _async = useRef<number>();\n let {\n value,\n textValue,\n minValue,\n maxValue,\n isDisabled,\n isReadOnly,\n isRequired,\n onIncrement,\n onIncrementPage,\n onDecrement,\n onDecrementPage,\n onDecrementToMin,\n onIncrementToMax\n } = props;\n const stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/spinbutton');\n\n const clearAsync = () => clearTimeout(_async.current);\n\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => clearAsync();\n }, []);\n\n let onKeyDown = (e) => {\n if (e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || isReadOnly) {\n return;\n }\n\n switch (e.key) {\n case 'PageUp':\n if (onIncrementPage) {\n e.preventDefault();\n onIncrementPage?.();\n break;\n }\n // fallthrough!\n case 'ArrowUp':\n case 'Up':\n if (onIncrement) {\n e.preventDefault();\n onIncrement?.();\n }\n break;\n case 'PageDown':\n if (onDecrementPage) {\n e.preventDefault();\n onDecrementPage?.();\n break;\n }\n // fallthrough\n case 'ArrowDown':\n case 'Down':\n if (onDecrement) {\n e.preventDefault();\n onDecrement?.();\n }\n break;\n case 'Home':\n if (onDecrementToMin) {\n e.preventDefault();\n onDecrementToMin?.();\n }\n break;\n case 'End':\n if (onIncrementToMax) {\n e.preventDefault();\n onIncrementToMax?.();\n }\n break;\n }\n };\n\n let isFocused = useRef(false);\n let onFocus = () => {\n isFocused.current = true;\n };\n\n let onBlur = () => {\n isFocused.current = false;\n };\n\n // Replace Unicode hyphen-minus (U+002D) with minus sign (U+2212).\n // This ensures that macOS VoiceOver announces it as \"minus\" even with other characters between the minus sign\n // and the number (e.g. currency symbol). Otherwise it announces nothing because it assumes the character is a hyphen.\n // In addition, replace the empty string with the word \"Empty\" so that iOS VoiceOver does not read \"50%\" for an empty field.\n let ariaTextValue = textValue === '' ? stringFormatter.format('Empty') : (textValue || `${value}`).replace('-', '\\u2212');\n\n useEffect(() => {\n if (isFocused.current) {\n clearAnnouncer('assertive');\n announce(ariaTextValue, 'assertive');\n }\n }, [ariaTextValue]);\n\n const onIncrementPressStart = useEffectEvent(\n (initialStepDelay: number) => {\n clearAsync();\n onIncrement?.();\n // Start spinning after initial delay\n _async.current = window.setTimeout(\n () => {\n if ((maxValue === undefined || isNaN(maxValue)) || (value === undefined || isNaN(value)) || value < maxValue) {\n onIncrementPressStart(60);\n }\n },\n initialStepDelay\n );\n }\n );\n\n const onDecrementPressStart = useEffectEvent(\n (initialStepDelay: number) => {\n clearAsync();\n onDecrement?.();\n // Start spinning after initial delay\n _async.current = window.setTimeout(\n () => {\n if ((minValue === undefined || isNaN(minValue)) || (value === undefined || isNaN(value)) || value > minValue) {\n onDecrementPressStart(60);\n }\n },\n initialStepDelay\n );\n }\n );\n\n let cancelContextMenu = (e) => {\n e.preventDefault();\n };\n\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n\n return {\n spinButtonProps: {\n role: 'spinbutton',\n 'aria-valuenow': value !== undefined && !isNaN(value) ? value : undefined,\n 'aria-valuetext': ariaTextValue,\n 'aria-valuemin': minValue,\n 'aria-valuemax': maxValue,\n 'aria-disabled': isDisabled || undefined,\n 'aria-readonly': isReadOnly || undefined,\n 'aria-required': isRequired || undefined,\n onKeyDown,\n onFocus,\n onBlur\n },\n incrementButtonProps: {\n onPressStart: () => {\n onIncrementPressStart(400);\n addGlobalListener(window, 'contextmenu', cancelContextMenu);\n },\n onPressEnd: () => {\n clearAsync();\n removeAllGlobalListeners();\n },\n onFocus,\n onBlur\n },\n decrementButtonProps: {\n onPressStart: () => {\n onDecrementPressStart(400);\n addGlobalListener(window, 'contextmenu', cancelContextMenu);\n },\n onPressEnd: () => {\n clearAsync();\n removeAllGlobalListeners();\n },\n onFocus,\n onBlur\n }\n };\n}\n"],"names":[],"version":3,"file":"useSpinButton.module.js.map"}
package/dist/zh-CN.mjs CHANGED
@@ -5,4 +5,4 @@ $d49d621f310cf6ce$exports = {
5
5
 
6
6
 
7
7
  export {$d49d621f310cf6ce$exports as default};
8
- //# sourceMappingURL=zh-CN.module.js.map
8
+ //# sourceMappingURL=zh-CN.mjs.map
package/dist/zh-TW.mjs CHANGED
@@ -5,4 +5,4 @@ $94b60c866ca5dfe6$exports = {
5
5
 
6
6
 
7
7
  export {$94b60c866ca5dfe6$exports as default};
8
- //# sourceMappingURL=zh-TW.module.js.map
8
+ //# sourceMappingURL=zh-TW.mjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/spinbutton",
3
- "version": "3.6.3",
3
+ "version": "3.6.4",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -22,11 +22,11 @@
22
22
  "url": "https://github.com/adobe/react-spectrum"
23
23
  },
24
24
  "dependencies": {
25
- "@react-aria/i18n": "^3.10.2",
26
- "@react-aria/live-announcer": "^3.3.2",
27
- "@react-aria/utils": "^3.23.2",
28
- "@react-types/button": "^3.9.2",
29
- "@react-types/shared": "^3.22.1",
25
+ "@react-aria/i18n": "^3.11.0",
26
+ "@react-aria/live-announcer": "^3.3.3",
27
+ "@react-aria/utils": "^3.24.0",
28
+ "@react-types/button": "^3.9.3",
29
+ "@react-types/shared": "^3.23.0",
30
30
  "@swc/helpers": "^0.5.0"
31
31
  },
32
32
  "peerDependencies": {
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "de9f84a22583fc741c29b341d14cd35ef4cca161"
39
+ "gitHead": "f645f29edc1322153fd60af4640cbcab1d992dbd"
40
40
  }