Skip to content

Commit

Permalink
fix: correct width calculation in resize component (#4170)
Browse files Browse the repository at this point in the history
  • Loading branch information
erha19 authored Nov 15, 2024
1 parent 36a2020 commit f81dbbf
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions packages/core-browser/src/components/resize/resize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,34 +258,33 @@ export const ResizeHandleHorizontal = (props: ResizeHandleProps) => {
const currentPrev = prevElement.current!.clientWidth;
const currentNext = nextElement.current!.clientWidth;

const nextTotolWidth = +nextElement.current!.style.width!.replace('%', '');
const prevTotalWidth = +prevElement.current!.style.width!.replace('%', '');
fastdom.mutate(() => {
const totalSize = currentPrev + currentNext;
if (props.flexMode) {
const prevWidth = props.flexMode === ResizeFlexMode.Prev ? size : totalSize - size;
const nextWidth = props.flexMode === ResizeFlexMode.Next ? size : totalSize - size;
flexModeSetSize(prevWidth, nextWidth, true);
} else {
const currentTotalWidth = nextTotolWidth + prevTotalWidth;

if (isLatter) {
nextElement.current!.style.width = currentTotalWidth * (size / totalSize) + '%';
prevElement.current!.style.width = currentTotalWidth * (1 - size / totalSize) + '%';
} else {
prevElement.current!.style.width = currentTotalWidth * (size / totalSize) + '%';
nextElement.current!.style.width = currentTotalWidth * (1 - size / totalSize) + '%';
}
}
const totalSize = currentPrev + currentNext;
if (props.flexMode) {
const prevWidth = props.flexMode === ResizeFlexMode.Prev ? size : totalSize - size;
const nextWidth = props.flexMode === ResizeFlexMode.Next ? size : totalSize - size;
flexModeSetSize(prevWidth, nextWidth, true);
} else {
const nextTotolWidth = +nextElement.current!.style.width!.replace('%', '');
const prevTotalWidth = +prevElement.current!.style.width!.replace('%', '');

const currentTotalWidth = nextTotolWidth + prevTotalWidth;

if (isLatter) {
handleZeroSize(totalSize - size, size);
nextElement.current!.style.width = currentTotalWidth * (size / totalSize) + '%';
prevElement.current!.style.width = currentTotalWidth * (1 - size / totalSize) + '%';
} else {
handleZeroSize(size, totalSize - size);
prevElement.current!.style.width = currentTotalWidth * (size / totalSize) + '%';
nextElement.current!.style.width = currentTotalWidth * (1 - size / totalSize) + '%';
}
if (props.onResize) {
props.onResize(prevElement.current!, nextElement.current!);
}
});
}
if (isLatter) {
handleZeroSize(totalSize - size, size);
} else {
handleZeroSize(size, totalSize - size);
}
if (props.onResize) {
props.onResize(prevElement.current!, nextElement.current!);
}
});
};

Expand Down

0 comments on commit f81dbbf

Please sign in to comment.