From da8934e879455cef4bfc6d035ae7ca3679dad4a8 Mon Sep 17 00:00:00 2001 From: Kalin Krustev Date: Tue, 15 Nov 2022 13:25:56 +0200 Subject: [PATCH] fix #3535 again (#3646) --- components/lib/splitter/Splitter.js | 4 +- components/lib/splitter/Splitter.spec.js | 22 ++++++ .../__snapshots__/Splitter.spec.js.snap | 69 +++++++++++++++++-- 3 files changed, 87 insertions(+), 8 deletions(-) diff --git a/components/lib/splitter/Splitter.js b/components/lib/splitter/Splitter.js index b99412953b..bbd1dcbe77 100644 --- a/components/lib/splitter/Splitter.js +++ b/components/lib/splitter/Splitter.js @@ -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({ diff --git a/components/lib/splitter/Splitter.spec.js b/components/lib/splitter/Splitter.spec.js index e10c4856c6..5c1cbe57e9 100644 --- a/components/lib/splitter/Splitter.spec.js +++ b/components/lib/splitter/Splitter.spec.js @@ -48,4 +48,26 @@ describe('Splitter', () => { , 'Nested' ); + snapshot( + <> + + Panel 1 + + , + 'Single Panel with size' + ); + snapshot( + <> + + Panel 1 + + , + 'Single Panel without size' + ); + snapshot( + <> + + , + 'Without panels' + ); }); diff --git a/components/lib/splitter/__snapshots__/Splitter.spec.js.snap b/components/lib/splitter/__snapshots__/Splitter.spec.js.snap index b2f82c41ab..fc135730f6 100644 --- a/components/lib/splitter/__snapshots__/Splitter.spec.js.snap +++ b/components/lib/splitter/__snapshots__/Splitter.spec.js.snap @@ -8,7 +8,7 @@ exports[`Splitter Nested 1`] = ` >
Panel 1
@@ -22,14 +22,14 @@ exports[`Splitter Nested 1`] = `
Panel 2
@@ -43,14 +43,14 @@ exports[`Splitter Nested 1`] = `
Panel 3
@@ -64,7 +64,7 @@ exports[`Splitter Nested 1`] = `
Panel 4
@@ -76,6 +76,54 @@ exports[`Splitter Nested 1`] = `
`; +exports[`Splitter Single Panel with size 1`] = ` +
+
+
+ Panel 1 +
+
+
+
+
+
+`; + +exports[`Splitter Single Panel without size 1`] = ` +
+
+
+ Panel 1 +
+
+
+
+
+
+`; + exports[`Splitter Splitter requires two SplitterPanel components to wrap. 1`] = `
`; + +exports[`Splitter Without panels 1`] = ` +
+
+
+`;