@@ -16,6 +16,7 @@ import {HTMLAttributes, useCallback, useEffect, useRef} from 'react';
16
16
import { InputBase , RangeInputBase , Validation , ValueBase } from '@react-types/shared' ;
17
17
// @ts -ignore
18
18
import intlMessages from '../intl/*.json' ;
19
+ import { useGlobalListeners } from '@react-aria/utils' ;
19
20
import { useMessageFormatter } from '@react-aria/i18n' ;
20
21
21
22
@@ -173,6 +174,8 @@ export function useSpinButton(
173
174
e . preventDefault ( ) ;
174
175
} ;
175
176
177
+ let { addGlobalListener, removeAllGlobalListeners} = useGlobalListeners ( ) ;
178
+
176
179
return {
177
180
spinButtonProps : {
178
181
role : 'spinbutton' ,
@@ -190,23 +193,23 @@ export function useSpinButton(
190
193
incrementButtonProps : {
191
194
onPressStart : ( ) => {
192
195
onIncrementPressStart ( 400 ) ;
193
- window . addEventListener ( 'contextmenu' , cancelContextMenu ) ;
196
+ addGlobalListener ( window , 'contextmenu' , cancelContextMenu ) ;
194
197
} ,
195
198
onPressEnd : ( ) => {
196
199
clearAsync ( ) ;
197
- window . removeEventListener ( 'contextmenu' , cancelContextMenu ) ;
200
+ removeAllGlobalListeners ( ) ;
198
201
} ,
199
202
onFocus,
200
203
onBlur
201
204
} ,
202
205
decrementButtonProps : {
203
206
onPressStart : ( ) => {
204
207
onDecrementPressStart ( 400 ) ;
205
- window . addEventListener ( 'contextmenu' , cancelContextMenu ) ;
208
+ addGlobalListener ( window , 'contextmenu' , cancelContextMenu ) ;
206
209
} ,
207
210
onPressEnd : ( ) => {
208
211
clearAsync ( ) ;
209
- window . removeEventListener ( 'contextmenu' , cancelContextMenu ) ;
212
+ removeAllGlobalListeners ( ) ;
210
213
} ,
211
214
onFocus,
212
215
onBlur
0 commit comments