Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Fix document reference when the grid is rendered in a popup window #14649

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading