Skip to content

Commit

Permalink
Fixed primefaces#5463 - Splitter/SplitterPanel: size not updated
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed Apr 1, 2024
1 parent 99ca280 commit cd18096
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions components/lib/splitter/Splitter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div :class="cx('root')" :style="sx('root')" :data-p-resizing="false" v-bind="ptmi('root', getPTOptions)">
<template v-for="(panel, i) of panels" :key="i">
<component :is="panel" tabindex="-1"></component>

<div
v-if="i !== panels.length - 1"
ref="gutter"
Expand Down Expand Up @@ -51,29 +52,10 @@ export default {
};
},
mounted() {
if (this.panels && this.panels.length) {
let initialized = false;
if (this.isStateful()) {
initialized = this.restoreState();
}
if (!initialized) {
let children = [...this.$el.children].filter((child) => child.getAttribute('data-pc-name') === 'splitterpanel');
let _panelSizes = [];
this.panels.map((panel, i) => {
let panelInitialSize = panel.props && panel.props.size ? panel.props.size : null;
let panelSize = panelInitialSize || 100 / this.panels.length;
_panelSizes[i] = panelSize;
children[i].style.flexBasis = 'calc(' + panelSize + '% - ' + (this.panels.length - 1) * this.gutterSize + 'px)';
});
this.panelSizes = _panelSizes;
this.prevSize = parseFloat(_panelSizes[0]).toFixed(4);
}
}
this.initializePanels();
},
updated() {
this.initializePanels();
},
beforeUnmount() {
this.clear();
Expand All @@ -83,6 +65,31 @@ export default {
isSplitterPanel(child) {
return child.type.name === 'SplitterPanel';
},
initializePanels() {
if (this.panels && this.panels.length) {
let initialized = false;
if (this.isStateful()) {
initialized = this.restoreState();
}
if (!initialized) {
let children = [...this.$el.children].filter((child) => child.getAttribute('data-pc-name') === 'splitterpanel');
let _panelSizes = [];
this.panels.map((panel, i) => {
let panelInitialSize = panel.props && panel.props.size ? panel.props.size : null;
let panelSize = panelInitialSize || 100 / this.panels.length;
_panelSizes[i] = panelSize;
children[i].style.flexBasis = 'calc(' + panelSize + '% - ' + (this.panels.length - 1) * this.gutterSize + 'px)';
});
this.panelSizes = _panelSizes;
this.prevSize = parseFloat(_panelSizes[0]).toFixed(4);
}
}
},
onResizeStart(event, index, isKeyDown) {
this.gutterElement = event.currentTarget || event.target.parentElement;
this.size = this.horizontal ? DomHandler.getWidth(this.$el) : DomHandler.getHeight(this.$el);
Expand Down

0 comments on commit cd18096

Please sign in to comment.