diff --git a/packages/x-data-grid/src/components/GridHeaders.tsx b/packages/x-data-grid/src/components/GridHeaders.tsx index 10a926d5ae9a..b6f2f6b290e0 100644 --- a/packages/x-data-grid/src/components/GridHeaders.tsx +++ b/packages/x-data-grid/src/components/GridHeaders.tsx @@ -54,11 +54,7 @@ function GridHeaders() { cellTabIndexState === null ); - const columnsContainerRef = React.useRef(null); - - apiRef.current.register('private', { - columnHeadersContainerRef: columnsContainerRef, - }); + const columnsContainerRef = apiRef.current.columnHeadersContainerRef; return ( ( const rootElementRef = React.useRef(null); const mainElementRef = React.useRef(null); const virtualScrollerRef = React.useRef(null); + const columnHeadersContainerRef = React.useRef(null); apiRef.current.register('public', { rootElementRef, @@ -15,5 +16,6 @@ export const useGridRefs = ( apiRef.current.register('private', { mainElementRef, virtualScrollerRef, + columnHeadersContainerRef, }); }; diff --git a/packages/x-data-grid/src/hooks/features/scroll/useGridScroll.ts b/packages/x-data-grid/src/hooks/features/scroll/useGridScroll.ts index 8e5f2ba8dab1..0c5543e0d12e 100644 --- a/packages/x-data-grid/src/hooks/features/scroll/useGridScroll.ts +++ b/packages/x-data-grid/src/hooks/features/scroll/useGridScroll.ts @@ -57,7 +57,7 @@ export const useGridScroll = ( ): void => { const theme = useTheme(); const logger = useGridLogger(apiRef, 'useGridScroll'); - const colRef = apiRef.current.columnHeadersContainerRef!; + const colRef = apiRef.current.columnHeadersContainerRef; const virtualScrollerRef = apiRef.current.virtualScrollerRef!; const visibleSortedRows = useGridSelector(apiRef, gridExpandedSortedRowEntriesSelector); diff --git a/packages/x-data-grid/src/models/api/gridCoreApi.ts b/packages/x-data-grid/src/models/api/gridCoreApi.ts index ac99d8652da1..8a48f4ee2412 100644 --- a/packages/x-data-grid/src/models/api/gridCoreApi.ts +++ b/packages/x-data-grid/src/models/api/gridCoreApi.ts @@ -75,7 +75,7 @@ export interface GridCorePrivateApi< /** * The React ref of the grid column container virtualized div element. */ - columnHeadersContainerRef?: React.RefObject; + columnHeadersContainerRef: React.RefObject; /** * The React ref of the grid header filter row element. */