Skip to content

Commit

Permalink
[DataGrid] Fix columnHeadersContainerRef being undefined before m…
Browse files Browse the repository at this point in the history
…ount (#14051)

Co-authored-by: Andrew Cherniavskii <[email protected]>
  • Loading branch information
samwato and cherniavskii authored Aug 1, 2024
1 parent eefc4a8 commit 345c769
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 7 deletions.
6 changes: 1 addition & 5 deletions packages/x-data-grid/src/components/GridHeaders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ function GridHeaders() {
cellTabIndexState === null
);

const columnsContainerRef = React.useRef<HTMLDivElement>(null);

apiRef.current.register('private', {
columnHeadersContainerRef: columnsContainerRef,
});
const columnsContainerRef = apiRef.current.columnHeadersContainerRef;

return (
<rootProps.slots.columnHeaders
Expand Down
2 changes: 2 additions & 0 deletions packages/x-data-grid/src/hooks/core/useGridRefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const useGridRefs = <PrivateApi extends GridPrivateApiCommon>(
const rootElementRef = React.useRef<HTMLDivElement>(null);
const mainElementRef = React.useRef<HTMLDivElement>(null);
const virtualScrollerRef = React.useRef<HTMLDivElement>(null);
const columnHeadersContainerRef = React.useRef<HTMLDivElement>(null);

apiRef.current.register('public', {
rootElementRef,
Expand All @@ -15,5 +16,6 @@ export const useGridRefs = <PrivateApi extends GridPrivateApiCommon>(
apiRef.current.register('private', {
mainElementRef,
virtualScrollerRef,
columnHeadersContainerRef,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion packages/x-data-grid/src/models/api/gridCoreApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export interface GridCorePrivateApi<
/**
* The React ref of the grid column container virtualized div element.
*/
columnHeadersContainerRef?: React.RefObject<HTMLDivElement>;
columnHeadersContainerRef: React.RefObject<HTMLDivElement>;
/**
* The React ref of the grid header filter row element.
*/
Expand Down

0 comments on commit 345c769

Please sign in to comment.