From 48e6087b1be1562c50de3b4aa648445df5510539 Mon Sep 17 00:00:00 2001 From: yhua1998 <385362330@qq.com> Date: Wed, 13 Sep 2023 16:55:31 +0800 Subject: [PATCH] fix: The width of the sidebar changes abruptly by dragging it multiple times over and over again (bouncing) --- app/components/sidebar.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/components/sidebar.tsx b/app/components/sidebar.tsx index db13bc9b42e..4519c4be941 100644 --- a/app/components/sidebar.tsx +++ b/app/components/sidebar.tsx @@ -67,7 +67,13 @@ function useDragSideBar() { lastUpdateTime.current = Date.now(); const d = e.clientX - startX.current; const nextWidth = limit(startDragWidth.current + d); - config.update((config) => (config.sidebarWidth = nextWidth)); + config.update((config) => { + if (nextWidth < MIN_SIDEBAR_WIDTH) { + config.sidebarWidth = NARROW_SIDEBAR_WIDTH; + } else { + config.sidebarWidth = nextWidth; + } + }); }); const handleMouseUp = useRef(() => { @@ -80,7 +86,7 @@ function useDragSideBar() { const onDragMouseDown = (e: MouseEvent) => { startX.current = e.clientX; // Remembers the initial width each time the mouse is pressed - startDragWidth.current = config.sidebarWidth + startDragWidth.current = config.sidebarWidth; window.addEventListener("mousemove", handleMouseMove.current); window.addEventListener("mouseup", handleMouseUp.current); };