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

Suppress invalid layout warning for empty panel groups #397

Merged
merged 1 commit into from
Aug 29, 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
21 changes: 21 additions & 0 deletions packages/react-resizable-panels/src/PanelGroup.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -418,5 +418,26 @@ describe("PanelGroup", () => {
ref.current?.setLayout([60, 80]);
});
});

it("should warn about an empty layout", () => {
act(() => {
root.render(
<PanelGroup direction="horizontal" id="group-without-handle">
<Panel />
</PanelGroup>
);
});

// Since the layout is empty, no warning is expected (even though the sizes won't total 100%)

act(() => {
root.render(
<PanelGroup
direction="horizontal"
id="group-without-handle"
></PanelGroup>
);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export function validatePanelGroupLayout({
.map((size) => `${size}%`)
.join(", ")}`
);
} else if (!fuzzyNumbersEqual(nextLayoutTotalSize, 100)) {
} else if (
!fuzzyNumbersEqual(nextLayoutTotalSize, 100) &&
nextLayout.length > 0
) {
// This is not ideal so we should warn about it, but it may be recoverable in some cases
// (especially if the amount is small)
if (isDevelopment) {
Expand Down
Loading