From dc70dd9279a24aada8a6a018c207e181453d3a75 Mon Sep 17 00:00:00 2001 From: Kiril Volskiy Date: Sun, 28 Apr 2024 22:29:16 +0300 Subject: [PATCH 1/2] fix: Splitter can work with multiple panels --- components/lib/splitter/Splitter.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/lib/splitter/Splitter.js b/components/lib/splitter/Splitter.js index b6f2ec729d..077e9a2a99 100644 --- a/components/lib/splitter/Splitter.js +++ b/components/lib/splitter/Splitter.js @@ -199,7 +199,9 @@ export const Splitter = React.memo( }; const onResizeEnd = (event) => { - const sizes = [prevPanelSizeNew.current, nextPanelSizeNew.current]; + let sizes = [...panelSizes]; + sizes[prevPanelIndex.current] = prevPanelSizeNew.current; + sizes[prevPanelIndex.current + 1] = nextPanelSizeNew.current; if (props.onResizeEnd) { props.onResizeEnd({ @@ -371,8 +373,11 @@ export const Splitter = React.memo( React.useEffect(() => { const panelElements = [...elementRef.current.children].filter((child) => DomHandler.getAttribute(child, 'data-pc-section') === 'splitterpanel.root'); + let _panelSizes = []; + panelElements.map((panelElement, i) => { prevSize.current = panelSize(panelSizes, 0); + _panelSizes[i] = panelSize(panelSizes, i); if (panelElement.childNodes && ObjectUtils.isNotEmpty(DomHandler.find(panelElement, "[data-pc-name='splitter']") && DomHandler.find(panelElement, "[data-pc-section='root']"))) { !isUnstyled() && DomHandler.addClass(panelElement, 'p-splitter-panel-nested'); @@ -380,6 +385,8 @@ export const Splitter = React.memo( setNested(true); } }); + + setPanelSizes(_panelSizes); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); From 36a99a93f5387cbc661e44d23a25babb8f174641 Mon Sep 17 00:00:00 2001 From: Kiril Volskiy Date: Mon, 29 Apr 2024 17:35:51 +0300 Subject: [PATCH 2/2] format --- components/lib/splitter/Splitter.js | 1 + 1 file changed, 1 insertion(+) diff --git a/components/lib/splitter/Splitter.js b/components/lib/splitter/Splitter.js index 077e9a2a99..a6dcd6371c 100644 --- a/components/lib/splitter/Splitter.js +++ b/components/lib/splitter/Splitter.js @@ -200,6 +200,7 @@ export const Splitter = React.memo( const onResizeEnd = (event) => { let sizes = [...panelSizes]; + sizes[prevPanelIndex.current] = prevPanelSizeNew.current; sizes[prevPanelIndex.current + 1] = nextPanelSizeNew.current;