Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup drag state when a resize handle unmounts while dragging #405

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/react-resizable-panels/src/PanelGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,7 @@ function PanelGroupWithForwardedRef({
[resizePanel]
);

// TODO Multiple drag handles can be active at the same time so this API is a bit awkward now
const startDragging = useCallback(
(dragHandleId: string, event: ResizeEvent) => {
const { direction } = committedValuesRef.current;
Expand Down
6 changes: 5 additions & 1 deletion packages/react-resizable-panels/src/PanelResizeHandle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,15 @@ export function PanelResizeHandle({
const setResizeHandlerState = (
action: ResizeHandlerAction,
isActive: boolean,
event: ResizeEvent
event: ResizeEvent | null
) => {
if (isActive) {
switch (action) {
case "down": {
setState("drag");

assert(event, 'Expected event to be defined for "down" action');

startDragging(resizeHandleId, event);

const { onDragging } = callbacksRef.current;
Expand All @@ -151,6 +153,8 @@ export function PanelResizeHandle({
setState("hover");
}

assert(event, 'Expected event to be defined for "move" action');

resizeHandler(event);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type ResizeHandlerAction = "down" | "move" | "up";
export type SetResizeHandlerState = (
action: ResizeHandlerAction,
isActive: boolean,
event: ResizeEvent
event: ResizeEvent | null
) => void;

export type PointerHitAreaMargins = {
Expand Down Expand Up @@ -83,6 +83,10 @@ export function registerResizeHandle(
}

updateCursor();

// Also instruct the handle to stop dragging; this prevents the parent group from being left in an inconsistent state
// See github.com/bvaughn/react-resizable-panels/issues/402
setResizeHandlerState("up", true, null);
}
};
}
Expand Down
Loading