Skip to content

Commit

Permalink
[DataGrid] Fix dimensions lag issue after autosize (mui#13587)
Browse files Browse the repository at this point in the history
  • Loading branch information
MBilalShafi authored and DungTiger committed Jul 23, 2024
1 parent 9c064d1 commit bc1d4eb
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function useGridDimensions(
const logger = useGridLogger(apiRef, 'useResizeContainer');
const errorShown = React.useRef(false);
const rootDimensionsRef = React.useRef(EMPTY_SIZE);
const dimensionsState = useGridSelector(apiRef, gridDimensionsSelector);
const rowsMeta = useGridSelector(apiRef, gridRowsMetaSelector);
const pinnedColumns = useGridSelector(apiRef, gridVisiblePinnedColumnDefinitionsSelector);
const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
Expand Down Expand Up @@ -302,26 +303,25 @@ export function useGridDimensions(
}, [apiRef, savedSize, updateDimensions]);

const root = apiRef.current.rootElementRef.current;
const dimensions = apiRef.current.state.dimensions;
useEnhancedEffect(() => {
if (!root) {
return;
}
const set = (k: string, v: string) => root.style.setProperty(k, v);
set('--DataGrid-width', `${dimensions.viewportOuterSize.width}px`);
set('--DataGrid-hasScrollX', `${Number(dimensions.hasScrollX)}`);
set('--DataGrid-hasScrollY', `${Number(dimensions.hasScrollY)}`);
set('--DataGrid-scrollbarSize', `${dimensions.scrollbarSize}px`);
set('--DataGrid-rowWidth', `${dimensions.rowWidth}px`);
set('--DataGrid-columnsTotalWidth', `${dimensions.columnsTotalWidth}px`);
set('--DataGrid-leftPinnedWidth', `${dimensions.leftPinnedWidth}px`);
set('--DataGrid-rightPinnedWidth', `${dimensions.rightPinnedWidth}px`);
set('--DataGrid-headerHeight', `${dimensions.headerHeight}px`);
set('--DataGrid-headersTotalHeight', `${dimensions.headersTotalHeight}px`);
set('--DataGrid-topContainerHeight', `${dimensions.topContainerHeight}px`);
set('--DataGrid-bottomContainerHeight', `${dimensions.bottomContainerHeight}px`);
set('--height', `${dimensions.rowHeight}px`);
}, [root, dimensions]);
set('--DataGrid-width', `${dimensionsState.viewportOuterSize.width}px`);
set('--DataGrid-hasScrollX', `${Number(dimensionsState.hasScrollX)}`);
set('--DataGrid-hasScrollY', `${Number(dimensionsState.hasScrollY)}`);
set('--DataGrid-scrollbarSize', `${dimensionsState.scrollbarSize}px`);
set('--DataGrid-rowWidth', `${dimensionsState.rowWidth}px`);
set('--DataGrid-columnsTotalWidth', `${dimensionsState.columnsTotalWidth}px`);
set('--DataGrid-leftPinnedWidth', `${dimensionsState.leftPinnedWidth}px`);
set('--DataGrid-rightPinnedWidth', `${dimensionsState.rightPinnedWidth}px`);
set('--DataGrid-headerHeight', `${dimensionsState.headerHeight}px`);
set('--DataGrid-headersTotalHeight', `${dimensionsState.headersTotalHeight}px`);
set('--DataGrid-topContainerHeight', `${dimensionsState.topContainerHeight}px`);
set('--DataGrid-bottomContainerHeight', `${dimensionsState.bottomContainerHeight}px`);
set('--height', `${dimensionsState.rowHeight}px`);
}, [root, dimensionsState]);

const isFirstSizing = React.useRef(true);
const handleResize = React.useCallback<GridEventListener<'resize'>>(
Expand Down

0 comments on commit bc1d4eb

Please sign in to comment.