Skip to content

Commit 4a9a26a

Browse files
committed
Fix dragging of bottom panel, but there is a small bug when mouse is dragged beyond the bottom panel or arrow button
1 parent cf97ab4 commit 4a9a26a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

app/src/components/bottom/BottomPanel.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef } from 'react';
1+
import React, { useEffect, useRef, useState } from 'react';
22
import BottomTabs from './BottomTabs';
33
import { ExpandLess, ExpandMore } from '@mui/icons-material';
44

@@ -7,6 +7,8 @@ const BottomPanel = (props): JSX.Element => {
77
let h: number = 0;
88
const node = useRef() as React.MutableRefObject<HTMLDivElement>;
99

10+
const [isDragging, setIsDragging] = useState(false);
11+
1012
const mouseDownHandler = (e): void => {
1113
y = e.clientY;
1214

@@ -28,6 +30,8 @@ const BottomPanel = (props): JSX.Element => {
2830
};
2931

3032
const mouseMoveHandler = function (e: MouseEvent): void {
33+
if (!props.bottomShow) return; // prevent drag calc to occur when bottom menu is not showing
34+
3135
const dy = y - e.clientY;
3236

3337
const newVal = h + dy;
@@ -37,6 +41,8 @@ const BottomPanel = (props): JSX.Element => {
3741
};
3842

3943
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);
4046
document.removeEventListener('mousemove', mouseMoveHandler);
4147
document.removeEventListener('mouseup', mouseUpHandler);
4248
window.removeEventListener('message', handleIframeMessage);
@@ -53,7 +59,9 @@ const BottomPanel = (props): JSX.Element => {
5359
<div
5460
id="resize-drag"
5561
onMouseDown={mouseDownHandler}
56-
onClick={() => props.setBottomShow(!props.bottomShow)}
62+
draggable
63+
onDragStart={() => setIsDragging(true)}
64+
onClick={() => !isDragging && props.setBottomShow(!props.bottomShow)}
5765
tabIndex={0}
5866
>
5967
{props.bottomShow ? <ExpandMore /> : <ExpandLess />}

0 commit comments

Comments
 (0)