Skip to content
Open
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test.meta({ browserSize: [800, 800] })('non resizable pane should not change its

await t
.expect(splitter.getItem(2).element.clientWidth)
.eql(145);
.eql(300);
}).before(async () => createWidget('dxSplitter', {
width: '100%',
height: 300,
Expand Down
199 changes: 197 additions & 2 deletions packages/devextreme/js/__internal/ui/splitter/splitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ import {
findIndexOfNextVisibleItem,
findLastIndexOfNonCollapsedItem,
findLastIndexOfVisibleItem,
findLastVisibleExpandedItemIndex,
getElementSize,
getNextLayout,
isElementVisible,
setFlexProp,
tryConvertToNumber,
} from './utils/layout';
import { getDefaultLayout } from './utils/layout_default';
import { compareNumbersWithPrecision } from './utils/number_comparison';
Expand Down Expand Up @@ -106,6 +108,7 @@ export interface Properties<
keyof PublicProperties<TItem, TKey>
> {
_renderQueue?: RenderQueueItem[];
_ignoreSizeConstraints?: boolean;
}

interface PaneCache {
Expand All @@ -128,12 +131,16 @@ class Splitter extends CollectionWidgetLiveUpdate<Properties> {

private _layout?: number[];

private _idealLayout?: number[];

private _currentLayout?: number[];

private _activeResizeHandleIndex?: number;

private _collapseDirection?: CollapseExpandDirection;

private _initialPaneSizes: (string | number | undefined)[] = [];

private _itemRestrictions: PaneRestrictions[] = [];

private _currentOnePxRatio?: number;
Expand All @@ -159,6 +166,7 @@ class Splitter extends CollectionWidgetLiveUpdate<Properties> {
role: 'group',
},
_renderQueue: undefined,
_ignoreSizeConstraints: false,
};
}

Expand Down Expand Up @@ -236,13 +244,23 @@ class Splitter extends CollectionWidgetLiveUpdate<Properties> {
}

_resizeHandler(): void {
if (this._shouldRecalculateLayout && this._isAttached() && this._isVisible()) {
if (!this._isAttached() || !this._isVisible()) {
return;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
const { _ignoreSizeConstraints } = this.option();

if (this._shouldRecalculateLayout) {
this._layout = this._getDefaultLayoutBasedOnSize();
this._idealLayout = this._layout;

this._applyStylesFromLayout(this._layout);
this._updateItemSizes();

this._shouldRecalculateLayout = false;
} else if (!_ignoreSizeConstraints) {
this._dimensionChanged();
}
}

Expand All @@ -252,8 +270,11 @@ class Splitter extends CollectionWidgetLiveUpdate<Properties> {
this._updateResizeHandlesResizableState();
this._updateResizeHandlesCollapsibleState();

this._initialPaneSizes = items.map((item: Item): string | number | undefined => item.size);

if (this._isVisible()) {
this._layout = this._getDefaultLayoutBasedOnSize();
this._idealLayout = this._layout;
this._applyStylesFromLayout(this._layout);

this._updateItemSizes();
Expand Down Expand Up @@ -537,6 +558,7 @@ class Splitter extends CollectionWidgetLiveUpdate<Properties> {

this._applyStylesFromLayout(newLayout);
this._layout = newLayout;
this._idealLayout = newLayout;
},
onResizeEnd: (e: ResizeEndEvent): void => {
const { element, event } = e;
Expand Down Expand Up @@ -663,6 +685,7 @@ class Splitter extends CollectionWidgetLiveUpdate<Properties> {
switch (property) {
case 'size':
this._layout = this._getDefaultLayoutBasedOnSize(item);
this._idealLayout = this._layout;

this._applyStylesFromLayout(this.getLayout());
this._updateItemSizes();
Expand All @@ -671,6 +694,7 @@ class Splitter extends CollectionWidgetLiveUpdate<Properties> {
case 'minSize':
case 'collapsedSize':
this._layout = this._getDefaultLayoutBasedOnSize();
this._idealLayout = this._layout;

this._applyStylesFromLayout(this.getLayout());
this._updateItemSizes();
Expand Down Expand Up @@ -757,6 +781,7 @@ class Splitter extends CollectionWidgetLiveUpdate<Properties> {
}

this._layout = newLayout;
this._idealLayout = this._layout;

this._applyStylesFromLayout(this.getLayout());
this._updateItemSizes();
Expand Down Expand Up @@ -1105,9 +1130,179 @@ class Splitter extends CollectionWidgetLiveUpdate<Properties> {
}

_dimensionChanged(): void {
// eslint-disable-next-line @typescript-eslint/naming-convention
const { _ignoreSizeConstraints } = this.option();

if (_ignoreSizeConstraints) {
this._updateItemSizes();

this._layout = this._getDefaultLayoutBasedOnSize();
return;
}

const idealLayout = this._idealLayout;

if (!idealLayout || idealLayout.length === 0) {
return;
}

const { orientation, items = [] } = this.option();
const elementSize = getElementSize(this.$element(), orientation);
const handlesSize = this._getResizeHandlesSize();
const availableSize = Math.max(0, elementSize - handlesSize);

if (availableSize <= 0) {
this._layout = idealLayout.map((): number => 0);
this._applyStylesFromLayout(this._layout);
this._updateItemSizes();
return;
}

const idealPixels = idealLayout.map((ratio: number): number => (ratio / 100) * availableSize);

let remaining = 0;
const newPixels = idealPixels.map((px: number, index: number): number => {
const item = items[index];

if (!item || item.visible === false) {
remaining += px;
return 0;
}

if (item.collapsed === true) {
const collapsedPx = tryConvertToNumber(item.collapsedSize, elementSize) ?? 0;
remaining += px - collapsedPx;
return collapsedPx;
}

if (item.resizable === false) {
const originalSize = this._initialPaneSizes[index];

if (isDefined(originalSize)) {
const fixedPx = tryConvertToNumber(originalSize, elementSize) ?? px;
Comment on lines +1179 to +1182
remaining += px - fixedPx;
return fixedPx;
}
}

const minPx = tryConvertToNumber(item.minSize, elementSize) ?? 0;
const maxPx = tryConvertToNumber(item.maxSize, elementSize);
const clampedPx = this._getClampedPixelSize(px, minPx, maxPx);

remaining += px - clampedPx;
return clampedPx;
});

this._distributeRemainingPixels(newPixels, remaining);

this._layout = newPixels.map((px: number): number => (px / availableSize) * 100);
this._applyStylesFromLayout(this._layout);
this._updateItemSizes();
}

_getEligiblePaneIndices(
pixels: number[],
remaining: number,
): number[] {
const { items = [], orientation } = this.option();
const elementSize = getElementSize(this.$element(), orientation);
const indices: number[] = [];
const direction = remaining > 0 ? 1 : -1;

for (let index = 0; index < pixels.length; index += 1) {
const item = items[index];

if (!item || item.visible === false || item.collapsed === true
|| (item.resizable === false && isDefined(this._initialPaneSizes[index]))) {
// skip
} else {
const minPx = tryConvertToNumber(item.minSize, elementSize) ?? 0;
const maxPx = tryConvertToNumber(item.maxSize, elementSize);
const clampedPx = this._getClampedPixelSize(pixels[index] + direction, minPx, maxPx);

if (compareNumbersWithPrecision(clampedPx, pixels[index]) !== 0) {
indices.push(index);
}
}
}

return indices;
}

_distributeRemainingPixels(
pixels: number[],
initialRemaining: number,
): void {
const { items = [] } = this.option();

let remaining = initialRemaining;

while (compareNumbersWithPrecision(remaining, 0) !== 0) {
const eligiblePaneIndices = this._getEligiblePaneIndices(pixels, remaining);

if (eligiblePaneIndices.length === 0) {
const fallback = findLastVisibleExpandedItemIndex(items);

if (fallback !== -1) {
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In _distributeRemainingPixels, the fallback path applies pixels[fallback] += remaining even when remaining is negative. If all panes are already clamped at their minSize (or fixed size), eligiblePaneIndices becomes empty and this can drive the fallback pane size below 0 (and below its min/max), resulting in negative flexGrow/sizes. Suggestion: only apply the fallback when remaining > 0 (extra space), and when remaining < 0 just stop distributing (allow overflow) or clamp the fallback so it cannot go below 0/minSize.

Suggested change
if (fallback !== -1) {
if (fallback !== -1 && remaining > 0) {

Copilot uses AI. Check for mistakes.
pixels[fallback] += remaining;
Comment on lines +1244 to +1247
}
break;
}

const share = remaining / eligiblePaneIndices.length;
const result = this._applyPixelShare(pixels, eligiblePaneIndices, share);

remaining -= result.applied;

if (!result.distributed) {
break;
}
}
}

_applyPixelShare(
pixels: number[],
eligiblePaneIndices: number[],
share: number,
): { applied: number; distributed: boolean } {
const { items = [], orientation } = this.option();
const elementSize = getElementSize(this.$element(), orientation);
let applied = 0;
let distributed = false;

eligiblePaneIndices.forEach((index: number): void => {
const item = items[index];
const prev = pixels[index];
const next = prev + share;

const minPx = tryConvertToNumber(item?.minSize, elementSize) ?? 0;
const maxPx = tryConvertToNumber(item?.maxSize, elementSize);
const clampedPx = this._getClampedPixelSize(next, minPx, maxPx);

const delta = clampedPx - prev;

if (compareNumbersWithPrecision(delta, 0) !== 0) {
pixels[index] = clampedPx;
applied += delta;
distributed = true;
}
});

return { applied, distributed };
}

_getClampedPixelSize(
size: number,
minPx: number,
maxPx: number | undefined,
): number {
let result = Math.max(size, minPx);

if (isDefined(maxPx)) {
result = Math.min(result, maxPx);
}

this._layout = this._getDefaultLayoutBasedOnSize();
return result;
}

_optionChanged(args: OptionChanged<Properties>): void {
Expand Down
Loading
Loading