From dc77d730f231a0d98a545b2a481005d40dfdbd4b Mon Sep 17 00:00:00 2001 From: fantasticit Date: Sun, 1 May 2022 13:12:14 +0800 Subject: [PATCH] fix: set width to be 100% if it is equal with maxWidth --- packages/client/src/components/resizeable/resizeable.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/client/src/components/resizeable/resizeable.tsx b/packages/client/src/components/resizeable/resizeable.tsx index b7ebe00..90d367a 100644 --- a/packages/client/src/components/resizeable/resizeable.tsx +++ b/packages/client/src/components/resizeable/resizeable.tsx @@ -29,6 +29,11 @@ function clamp(val: number, min: number, max: number): string { return '' + val; } +function calcWidth(width, minWidth, maxWidth) { + const val = parseInt(clamp(width, minWidth, maxWidth || Infinity)); + return val === maxWidth ? '100%' : val; +} + export const Resizeable: React.FC = ({ width, height, @@ -72,7 +77,7 @@ export const Resizeable: React.FC = ({ const cloneNode = $cloneNode.current; let { width, height } = event.rect; - width = parseInt(clamp(width, MIN_WIDTH, maxWidth || Infinity)); + width = calcWidth(width, MIN_WIDTH, maxWidth || Infinity); height = parseInt(clamp(height, MIN_HEIGHT, Infinity)); Object.assign(cloneNode.style, { width: `${width}px`, @@ -87,7 +92,7 @@ export const Resizeable: React.FC = ({ }, end: function (event) { let { width, height } = event.rect; - width = clamp(width, MIN_WIDTH, maxWidth || Infinity); + width = calcWidth(width, MIN_WIDTH, maxWidth || Infinity); height = clamp(height, MIN_HEIGHT, Infinity); const cloneNode = $cloneNode.current;