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

fix #3535 regression #3646

Merged
merged 1 commit into from
Nov 15, 2022
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
4 changes: 2 additions & 2 deletions components/lib/splitter/Splitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ export const Splitter = React.memo(
const prevPanelIndex = React.useRef(null);
const [panelSizes, setPanelSizes] = React.useState([]);
const isStateful = props.stateKey != null;
const childrenLength = props.children && props.children.length;
const panelSize = (sizes, index) => (index in sizes ? sizes[index] : ((props.children[index] && props.children[index].props.size) || 100) / childrenLength);
const childrenLength = (props.children && props.children.length) || 1;
const panelSize = (sizes, index) => (index in sizes ? sizes[index] : (props.children && [].concat(props.children)[index].props.size) || 100 / childrenLength);

const [bindDocumentMouseMoveListener, unbindDocumentMouseMoveListener] = useEventListener({ type: 'mousemove', listener: (event) => onResize(event) });
const [bindDocumentMouseUpListener, unbindDocumentMouseUpListener] = useEventListener({
Expand Down
22 changes: 22 additions & 0 deletions components/lib/splitter/Splitter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,26 @@ describe('Splitter', () => {
</>,
'Nested'
);
snapshot(
<>
<Splitter style={{ height: '300px' }} layout="vertical">
<SplitterPanel size={5}>Panel 1</SplitterPanel>
</Splitter>
</>,
'Single Panel with size'
);
snapshot(
<>
<Splitter style={{ height: '300px' }} layout="vertical">
<SplitterPanel>Panel 1</SplitterPanel>
</Splitter>
</>,
'Single Panel without size'
);
snapshot(
<>
<Splitter style={{ height: '300px' }} layout="vertical"></Splitter>
</>,
'Without panels'
);
});
69 changes: 63 additions & 6 deletions components/lib/splitter/__snapshots__/Splitter.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports[`Splitter Nested 1`] = `
>
<div
class="p-splitter-panel flex align-items-center justify-content-center"
style="flex-basis: calc(10% - 4px);"
style="flex-basis: calc(20% - 4px);"
>
Panel 1
</div>
Expand All @@ -22,14 +22,14 @@ exports[`Splitter Nested 1`] = `
</div>
<div
class="p-splitter-panel p-splitter-panel-nested"
style="flex-basis: calc(40% - 4px);"
style="flex-basis: calc(80% - 4px);"
>
<div
class="p-splitter p-component p-splitter-vertical"
>
<div
class="p-splitter-panel flex align-items-center justify-content-center"
style="flex-basis: calc(7.5% - 4px);"
style="flex-basis: calc(15% - 4px);"
>
Panel 2
</div>
Expand All @@ -43,14 +43,14 @@ exports[`Splitter Nested 1`] = `
</div>
<div
class="p-splitter-panel p-splitter-panel-nested"
style="flex-basis: calc(42.5% - 4px);"
style="flex-basis: calc(85% - 4px);"
>
<div
class="p-splitter p-component p-splitter-horizontal"
>
<div
class="p-splitter-panel flex align-items-center justify-content-center"
style="flex-basis: calc(10% - 4px);"
style="flex-basis: calc(20% - 4px);"
>
Panel 3
</div>
Expand All @@ -64,7 +64,7 @@ exports[`Splitter Nested 1`] = `
</div>
<div
class="p-splitter-panel flex align-items-center justify-content-center"
style="flex-basis: calc(40% - 4px);"
style="flex-basis: calc(80% - 4px);"
>
Panel 4
</div>
Expand All @@ -76,6 +76,54 @@ exports[`Splitter Nested 1`] = `
</div>
`;

exports[`Splitter Single Panel with size 1`] = `
<div>
<div
class="p-splitter p-component p-splitter-vertical"
style="height: 300px;"
>
<div
class="p-splitter-panel"
style="flex-basis: calc(5% - 0px);"
>
Panel 1
</div>
<div
class="p-splitter-gutter"
style="height: 4px;"
>
<div
class="p-splitter-gutter-handle"
/>
</div>
</div>
</div>
`;

exports[`Splitter Single Panel without size 1`] = `
<div>
<div
class="p-splitter p-component p-splitter-vertical"
style="height: 300px;"
>
<div
class="p-splitter-panel"
style="flex-basis: calc(100% - 0px);"
>
Panel 1
</div>
<div
class="p-splitter-gutter"
style="height: 4px;"
>
<div
class="p-splitter-gutter-handle"
/>
</div>
</div>
</div>
`;

exports[`Splitter Splitter requires two SplitterPanel components to wrap. 1`] = `
<div>
<div
Expand Down Expand Up @@ -135,3 +183,12 @@ exports[`Splitter Vertical layout 1`] = `
</div>
</div>
`;

exports[`Splitter Without panels 1`] = `
<div>
<div
class="p-splitter p-component p-splitter-vertical"
style="height: 300px;"
/>
</div>
`;