1
- import React , { useEffect , useRef } from 'react' ;
1
+ import React , { useEffect , useRef , useState } from 'react' ;
2
2
import BottomTabs from './BottomTabs' ;
3
3
import { ExpandLess , ExpandMore } from '@mui/icons-material' ;
4
4
@@ -7,6 +7,8 @@ const BottomPanel = (props): JSX.Element => {
7
7
let h : number = 0 ;
8
8
const node = useRef ( ) as React . MutableRefObject < HTMLDivElement > ;
9
9
10
+ const [ isDragging , setIsDragging ] = useState ( false ) ;
11
+
10
12
const mouseDownHandler = ( e ) : void => {
11
13
y = e . clientY ;
12
14
@@ -28,6 +30,8 @@ const BottomPanel = (props): JSX.Element => {
28
30
} ;
29
31
30
32
const mouseMoveHandler = function ( e : MouseEvent ) : void {
33
+ if ( ! props . bottomShow ) return ; // prevent drag calc to occur when bottom menu is not showing
34
+
31
35
const dy = y - e . clientY ;
32
36
33
37
const newVal = h + dy ;
@@ -37,6 +41,8 @@ const BottomPanel = (props): JSX.Element => {
37
41
} ;
38
42
39
43
const mouseUpHandler = function ( ) {
44
+ // puts false in callback queue after OnDragStart sets to true (b/c react 17 doesn't have onDragEnd)
45
+ setTimeout ( ( ) => setIsDragging ( false ) , 0 ) ;
40
46
document . removeEventListener ( 'mousemove' , mouseMoveHandler ) ;
41
47
document . removeEventListener ( 'mouseup' , mouseUpHandler ) ;
42
48
window . removeEventListener ( 'message' , handleIframeMessage ) ;
@@ -53,7 +59,9 @@ const BottomPanel = (props): JSX.Element => {
53
59
< div
54
60
id = "resize-drag"
55
61
onMouseDown = { mouseDownHandler }
56
- onClick = { ( ) => props . setBottomShow ( ! props . bottomShow ) }
62
+ draggable
63
+ onDragStart = { ( ) => setIsDragging ( true ) }
64
+ onClick = { ( ) => ! isDragging && props . setBottomShow ( ! props . bottomShow ) }
57
65
tabIndex = { 0 }
58
66
>
59
67
{ props . bottomShow ? < ExpandMore /> : < ExpandLess /> }
0 commit comments