Skip to content

Commit

Permalink
fix: Splitter can work with multiple panels
Browse files Browse the repository at this point in the history
  • Loading branch information
KirilCycle authored and melloware committed Apr 29, 2024
1 parent b3d109a commit dc70dd9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion components/lib/splitter/Splitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -371,15 +373,20 @@ 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');
panelElement.setAttribute('data-p-splitter-panel-nested', true);
setNested(true);
}
});

setPanelSizes(_panelSizes);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

Expand Down

0 comments on commit dc70dd9

Please sign in to comment.