Skip to content

Commit 471c52f

Browse files
committed
Fix for no onResizeEnd() event if space not resized but resize action started and removed erroneous conditional callback
1 parent 224a46c commit 471c52f

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

react-spaces/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-spaces",
3-
"version": "0.1.20-alpha.3",
3+
"version": "0.1.20-alpha.4",
44
"main": "dist/index.js",
55
"module": "dist/es/index.js",
66
"types": "dist/index.d.ts",

react-spaces/src/Space.tsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,22 @@ export const SpaceInternal : React.FC<AllProps> = React.memo((props) => {
4949
const overlayHandle = props.overlayHandle !== undefined ? props.overlayHandle : true;
5050
let resizeType: ResizeType | undefined = undefined;
5151
let resizeHandle: React.ReactNode | undefined = undefined;
52+
const onResizeEnd = React.useCallback(() => {
53+
if (divElementRef.current)
54+
{
55+
const currentRect = divElementRef.current.getBoundingClientRect();
56+
props.onResizeEnd && props.onResizeEnd(
57+
Math.floor(resizeType === ResizeType.Left || resizeType === ResizeType.Right ? currentRect.width : currentRect.height)
58+
);
59+
}
60+
}, []);
5261

5362
if (parentContext && props.anchor && props.resizable) {
5463
resizeType = AnchorToResizeTypeMap[props.anchor];
5564

5665
const resizeHandleWidth = resizeType === ResizeType.Left || resizeType === ResizeType.Right ? handleSize : undefined;
5766
const resizeHandleHeight = resizeType === ResizeType.Top || resizeType === ResizeType.Bottom ? handleSize : undefined;
5867

59-
const onResizeEnd = React.useCallback(() => {
60-
if (divElementRef.current)
61-
{
62-
const currentRect = divElementRef.current.getBoundingClientRect();
63-
props.onResizeEnd && props.onResizeEnd(
64-
Math.floor(resizeType === ResizeType.Left || resizeType === ResizeType.Right ? currentRect.width : currentRect.height)
65-
);
66-
}
67-
}, []);
68-
6968
const onResize = (
7069
originalX: number,
7170
originalY: number,
@@ -124,7 +123,7 @@ export const SpaceInternal : React.FC<AllProps> = React.memo((props) => {
124123
}
125124
window.removeEventListener('touchmove', withPreventDefault);
126125
window.removeEventListener('touchend', removeListener);
127-
moved && onResizeEnd();
126+
onResizeEnd();
128127
};
129128
window.addEventListener('touchmove', withPreventDefault);
130129
window.addEventListener('touchend', removeListener);
@@ -165,7 +164,7 @@ export const SpaceInternal : React.FC<AllProps> = React.memo((props) => {
165164
}
166165
window.removeEventListener('mousemove', withPreventDefault);
167166
window.removeEventListener('mouseup', removeListener);
168-
moved && onResizeEnd();
167+
onResizeEnd();
169168
};
170169
window.addEventListener('mousemove', withPreventDefault);
171170
window.addEventListener('mouseup', removeListener);

0 commit comments

Comments
 (0)