Skip to content

Commit

Permalink
fix: The width of the sidebar changes abruptly by dragging it multipl…
Browse files Browse the repository at this point in the history
…e times over and over again (bouncing)
  • Loading branch information
kehuay committed Sep 13, 2023
1 parent 28103c9 commit 48e6087
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/components/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -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);
};
Expand Down

0 comments on commit 48e6087

Please sign in to comment.