Skip to content

Commit

Permalink
Update document reference once root element reference is available
Browse files Browse the repository at this point in the history
  • Loading branch information
arminmeh committed Sep 17, 2024
1 parent 149cecd commit bf04188
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const useGridCellSelection = (
| 'columnHeaderHeight'
>,
) => {
const hasRootReference = apiRef.current.rootElementRef.current !== null;
const visibleRows = useGridVisibleRows(apiRef, props);
const cellWithVirtualFocus = React.useRef<GridCellCoordinates | null>();
const lastMouseDownCell = React.useRef<GridCellCoordinates | null>();
Expand Down Expand Up @@ -476,7 +477,7 @@ export const useGridCellSelection = (
const document = ownerDocument(rootRef);
document.removeEventListener('mouseup', handleMouseUp);
};
}, [apiRef, handleMouseUp, stopAutoScroll]);
}, [apiRef, hasRootReference, handleMouseUp, stopAutoScroll]);

const checkIfCellIsSelected = React.useCallback<GridPipeProcessor<'isCellSelected'>>(
(isSelected, { id, field }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const useGridPrintExport = (
apiRef: React.MutableRefObject<GridPrivateApiCommunity>,
props: Pick<DataGridProcessedProps, 'pagination' | 'columnHeaderHeight' | 'headerFilterHeight'>,
): void => {
const hasRootReference = apiRef.current.rootElementRef.current !== null;
const logger = useGridLogger(apiRef, 'useGridPrintExport');
const doc = React.useRef<Document | null>(null);
const previousGridState = React.useRef<GridInitialStateCommunity | null>(null);
Expand All @@ -76,7 +77,7 @@ export const useGridPrintExport = (

React.useEffect(() => {
doc.current = ownerDocument(apiRef.current.rootElementRef!.current!);
}, [apiRef]);
}, [apiRef, hasRootReference]);

// Returns a promise because updateColumns triggers state update and
// the new state needs to be in place before the grid can be sized correctly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const useGridFocus = (
const logger = useGridLogger(apiRef, 'useGridFocus');

const lastClickedCell = React.useRef<GridCellParams | null>(null);
const hasRootReference = apiRef.current.rootElementRef.current !== null;

const publishCellFocusOut = React.useCallback(
(cell: GridCellCoordinates | null, event: GridEventLookup['cellFocusOut']['event']) => {
Expand Down Expand Up @@ -489,7 +490,7 @@ export const useGridFocus = (
return () => {
doc.removeEventListener('mouseup', handleDocumentClick);
};
}, [apiRef, handleDocumentClick]);
}, [apiRef, hasRootReference, handleDocumentClick]);

useGridApiEventHandler(apiRef, 'columnHeaderBlur', handleBlur);
useGridApiEventHandler(apiRef, 'cellDoubleClick', handleCellDoubleClick);
Expand Down

0 comments on commit bf04188

Please sign in to comment.