Skip to content

Commit

Permalink
fix: Collapsed panel no longer grows when not pushed by a sibling panel
Browse files Browse the repository at this point in the history
  • Loading branch information
b-zurg committed Jun 19, 2020
1 parent 92d6dd4 commit 8f85b7f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/components/SplitPane/hooks/callbacks/useGetMovedSizes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,52 @@ export function useGetMovedSizes({
isLtr,
minSizes,
collapsedIndices,
isReversed,
collapsedSize,
}: {
sizes: number[];
isLtr: boolean;
minSizes: number[];
collapsedIndices: number[];
isReversed: boolean;
collapsedSize: number;
}) {
return useCallback(
(dragState: DragState<ResizeState> | null): number[] => {
if (!dragState) return originalSizes;
const sizes = [...originalSizes];
const index = dragState.extraState.index;
const offset = isLtr ? dragState.offset : -dragState.offset;
moveSizes({
sizes: sizes,
index: dragState.extraState.index,
offset: isLtr ? dragState.offset : -dragState.offset,
index,
offset,
minSizes,
collapsedIndices,
collapsedSize,
});
// must move all previously collapsed panes as well, slightly different to what happens when collapsing, though mostly identical
if (isReversed ? offset > 0 : offset < 0) {
for (
let i = isReversed ? index : index + 1;
isReversed ? i > 0 : i < sizes.length - 1;
isReversed ? i-- : i++
) {
if (collapsedIndices.includes(i)) {
moveSizes({
sizes,
index: isReversed ? i - 1 : i,
offset,
minSizes,
collapsedIndices,
collapsedSize,
});
}
}
}

return sizes;
},
[collapsedIndices, collapsedSize, isLtr, minSizes, originalSizes]
[collapsedIndices, collapsedSize, isLtr, isReversed, minSizes, originalSizes]
);
}
1 change: 1 addition & 0 deletions src/components/SplitPane/hooks/useSplitPaneResize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export function useSplitPaneResize(options: SplitPaneResizeOptions): SplitPaneRe
isLtr,
collapsedSize,
collapsedIndices,
isReversed,
});
const getCurrentPaneSizes = useGetCurrentPaneSizes({ childPanes, split });
const handleDragFinished = useHandleDragFinished({ getMovedSizes, children, hooks, setSizes });
Expand Down

0 comments on commit 8f85b7f

Please sign in to comment.