diff --git a/packages/grid/x-data-grid/src/hooks/features/dimensions/useGridDimensions.ts b/packages/grid/x-data-grid/src/hooks/features/dimensions/useGridDimensions.ts index edc946f3641a2..c6c9a19877f7a 100644 --- a/packages/grid/x-data-grid/src/hooks/features/dimensions/useGridDimensions.ts +++ b/packages/grid/x-data-grid/src/hooks/features/dimensions/useGridDimensions.ts @@ -220,8 +220,8 @@ export function useGridDimensions( return; } - const height = mainEl.offsetHeight || 0; - const width = mainEl.offsetWidth || 0; + const height = mainEl.clientHeight || 0; + const width = mainEl.clientWidth || 0; const win = ownerWindow(mainEl); diff --git a/packages/grid/x-data-grid/src/tests/layout.DataGrid.test.tsx b/packages/grid/x-data-grid/src/tests/layout.DataGrid.test.tsx index c6b4943c68897..4f8d757eafb60 100644 --- a/packages/grid/x-data-grid/src/tests/layout.DataGrid.test.tsx +++ b/packages/grid/x-data-grid/src/tests/layout.DataGrid.test.tsx @@ -12,7 +12,7 @@ import { } from '@mui/x-data-grid'; import { useBasicDemoData } from '@mui/x-data-grid-generator'; import { createTheme, ThemeProvider } from '@mui/material/styles'; -import { getColumnHeaderCell, getColumnValues, getCell, getRow } from 'test/utils/helperFn'; +import { getColumnHeaderCell, getColumnValues, getCell, getRow, sleep } from 'test/utils/helperFn'; describe(' - Layout & Warnings', () => { const { clock, render } = createRenderer(); @@ -1099,4 +1099,32 @@ describe(' - Layout & Warnings', () => { }); }); }); + + // See https://github.com/mui/mui-x/issues/8737 + it('should not add horizontal scrollbar when .MuiDataGrid-main has border', async function test() { + if (/jsdom/.test(window.navigator.userAgent)) { + // Need layouting + this.skip(); + } + + render( +
+ +
, + ); + + const virtualScroller = document.querySelector('.MuiDataGrid-virtualScroller')!; + const initialVirtualScrollerWidth = virtualScroller.clientWidth; + + // It should not have a horizontal scrollbar + expect(virtualScroller.scrollWidth - virtualScroller.clientWidth).to.equal(0); + + await sleep(200); + // The width should not increase infinitely + expect(virtualScroller.clientWidth).to.equal(initialVirtualScrollerWidth); + }); });