From 1a0b8d21ab586d25e43ba3db70fae5c5f8504e2b Mon Sep 17 00:00:00 2001 From: gizeasy Date: Wed, 3 Dec 2025 19:13:25 +0300 Subject: [PATCH] fix(Table): width cell closes #3900 --- .../TableBody/useResizableColumns/helpers.ts | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/components/Table/TableBody/useResizableColumns/helpers.ts b/src/components/Table/TableBody/useResizableColumns/helpers.ts index e709dfd..0121038 100644 --- a/src/components/Table/TableBody/useResizableColumns/helpers.ts +++ b/src/components/Table/TableBody/useResizableColumns/helpers.ts @@ -33,7 +33,9 @@ export const sizesEq = ( const getContainerWidth = (el?: HTMLElement | null) => el - ? el.clientWidth - (el.offsetWidth - el.getBoundingClientRect().width) + ? Math.floor( + el.clientWidth - (el.offsetWidth - el.getBoundingClientRect().width), + ) : undefined; export const getRefsSizes = ( @@ -47,7 +49,8 @@ export const getRefsSizes = ( (typeof width === 'number' ? minMax(minWidth, maxWidth, width) : width); if (typeof value === 'number') { - const roundValue = Math.round(value + gap); + const roundValue = Math.floor(value + gap); + gap += value - roundValue; return roundValue; @@ -92,10 +95,7 @@ export const isSizesCalculate = ( (item) => typeof item === 'string' || typeof item === 'undefined', ); -export const getSizesSum = (sizes: number[]) => - sizes.reduce((a, b) => { - return a + b; - }); +export const getSizesSum = (sizes: number[]) => sizes.reduce((a, b) => a + b); const getValidValues = ( value: number, @@ -146,13 +146,16 @@ const getValidValues = ( const sizesSum = getSizesSum(addResult(results, newSizes)); - if ( - (resizable === 'inside' && sizesSum !== containerWidth) || - (resizable === 'outside' && sizesSum < containerWidth) - ) { + if (resizable === 'inside' && sizesSum !== containerWidth) { return []; } + if (resizable === 'outside' && sizesSum < containerWidth) { + newSizes.splice(index, 1, 0); + + return [[index, containerWidth - getSizesSum(newSizes)]]; + } + return results; }; @@ -172,7 +175,7 @@ export const getCalculatedSizes = ( const scrollLeft = container.current?.scrollLeft || 0; const trackPosition = getTargetBlockPosition(sizes, index); - const value = Math.round( + const value = Math.floor( position + scrollLeft - containerLeft - trackPosition, );