@@ -15,7 +15,8 @@ export interface MouseContext {
1515}
1616
1717type MouseEventOptions = {
18- enableTouch ?: boolean ;
18+ enabled ?: boolean ;
19+ enableTouch ?: boolean ; // 支持触摸事件
1920 onDown ?: ( e : MouseCallback , ctx : MouseContext ) => void ;
2021 onMove ?: ( e : MouseCallback , ctx : MouseContext ) => void ;
2122 onUp ?: ( e : MouseCallback , ctx : MouseContext ) => void ;
@@ -24,7 +25,7 @@ type MouseEventOptions = {
2425} ;
2526
2627const useMouseEvent = ( elementRef : React . RefObject < HTMLElement > , options : MouseEventOptions ) => {
27- const { enableTouch = true } = options ; // 默认支持触摸事件
28+ const { enabled = true , enableTouch = true } = options ;
2829 const isMovingRef = useRef ( false ) ;
2930
3031 const normalizeEvent = ( e : MouseEventLike ) => {
@@ -100,7 +101,7 @@ const useMouseEvent = (elementRef: React.RefObject<HTMLElement>, options: MouseE
100101
101102 useEffect ( ( ) => {
102103 const el = elementRef . current ;
103- if ( ! el ) return ;
104+ if ( ! el || ! enabled ) return ;
104105
105106 // 基本上只要开启了鼠标事件,就会用到这三个
106107 // 有的组件虽然只需要 mousemove 的回调结果,但也需要 mousedown 和 mouseup 来控制状态
@@ -125,7 +126,7 @@ const useMouseEvent = (elementRef: React.RefObject<HTMLElement>, options: MouseE
125126 el . removeEventListener ( 'touchend' , handleMouseUp ) ;
126127 } ;
127128 // eslint-disable-next-line react-hooks/exhaustive-deps
128- } , [ elementRef . current , options ] ) ;
129+ } , [ elementRef . current , options , enabled ] ) ;
129130
130131 return {
131132 isMoving : isMovingRef . current ,
0 commit comments