fix: set width to be 100% if it is equal with maxWidth

This commit is contained in:
fantasticit 2022-05-01 13:12:14 +08:00
parent c1a4e4b35e
commit dc77d730f2
1 changed files with 7 additions and 2 deletions

View File

@ -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<IProps> = ({
width,
height,
@ -72,7 +77,7 @@ export const Resizeable: React.FC<IProps> = ({
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<IProps> = ({
},
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;