File tree Expand file tree Collapse file tree 1 file changed +11
-12
lines changed
Expand file tree Collapse file tree 1 file changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,11 @@ export const Button = React.forwardRef(Button_);
7474
7575const repeatInterval = 500 ;
7676
77+ function isLeftButtonOrTouch ( e )
78+ {
79+ return e . button === 0 || typeof e . touches != 'undefined' ;
80+ }
81+
7782export class RepeatingButton extends React . PureComponent
7883{
7984 constructor ( props )
@@ -112,26 +117,20 @@ export class RepeatingButton extends React.PureComponent
112117
113118 handleStart ( e )
114119 {
115- if ( e . button !== 0 && typeof e . touches === 'undefined' )
120+ if ( ! isLeftButtonOrTouch ( e ) || this . intervalId )
116121 return ;
117122
118- if ( ! this . intervalId )
119- {
120- this . hasInitialClick = false ;
121- this . intervalId = setInterval ( this . handleTimer , repeatInterval ) ;
122- }
123+ this . hasInitialClick = false ;
124+ this . intervalId = setInterval ( this . handleTimer , repeatInterval ) ;
123125 }
124126
125127 handleEnd ( e )
126128 {
127- if ( e . button !== 0 && typeof e . touches === 'undefined' )
129+ if ( ! isLeftButtonOrTouch ( e ) || ! this . intervalId )
128130 return ;
129131
130- if ( this . intervalId )
131- {
132- clearInterval ( this . intervalId ) ;
133- this . intervalId = null ;
134- }
132+ clearInterval ( this . intervalId ) ;
133+ this . intervalId = null ;
135134 }
136135
137136 render ( )
You can’t perform that action at this time.
0 commit comments