From bf1a30cb1ad2bfa82194230af76620fc1f246593 Mon Sep 17 00:00:00 2001 From: Andrew Cherniavskii Date: Wed, 10 Apr 2024 16:47:01 +0200 Subject: [PATCH 1/2] [DataGridPremium] Fix clipboard paste not working when cell loses focus (#12724) --- .../features/clipboard/useGridClipboardImport.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/grid/x-data-grid-premium/src/hooks/features/clipboard/useGridClipboardImport.ts b/packages/grid/x-data-grid-premium/src/hooks/features/clipboard/useGridClipboardImport.ts index c6888c8d70879..9b903dd6bf189 100644 --- a/packages/grid/x-data-grid-premium/src/hooks/features/clipboard/useGridClipboardImport.ts +++ b/packages/grid/x-data-grid-premium/src/hooks/features/clipboard/useGridClipboardImport.ts @@ -220,8 +220,9 @@ function defaultPasteResolver({ }) { const isSingleValuePasted = pastedData.length === 1 && pastedData[0].length === 1; - const cellSelectionModel = apiRef.current.unstable_getCellSelectionModel(); - if (cellSelectionModel && apiRef.current.unstable_getSelectedCellsAsArray().length > 1) { + const cellSelectionModel = apiRef.current.getCellSelectionModel(); + const selectedCellsArray = apiRef.current.getSelectedCellsAsArray(); + if (cellSelectionModel && selectedCellsArray.length > 1) { Object.keys(cellSelectionModel).forEach((rowId, rowIndex) => { const rowDataArr = pastedData[isSingleValuePasted ? 0 : rowIndex]; const hasRowData = isSingleValuePasted ? true : rowDataArr !== undefined; @@ -276,7 +277,11 @@ function defaultPasteResolver({ return; } - const selectedCell = gridFocusCellSelector(apiRef); + let selectedCell = gridFocusCellSelector(apiRef); + if (!selectedCell && selectedCellsArray.length === 1) { + selectedCell = selectedCellsArray[0]; + } + if (!selectedCell) { return; } From 8b8a4b03eed53017e4bc579dc46aafae684f8a5f Mon Sep 17 00:00:00 2001 From: Andrew Cherniavskyi Date: Mon, 27 May 2024 21:00:43 +0200 Subject: [PATCH 2/2] fix methods names --- .../src/hooks/features/clipboard/useGridClipboardImport.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/grid/x-data-grid-premium/src/hooks/features/clipboard/useGridClipboardImport.ts b/packages/grid/x-data-grid-premium/src/hooks/features/clipboard/useGridClipboardImport.ts index 9b903dd6bf189..33c3110c6add0 100644 --- a/packages/grid/x-data-grid-premium/src/hooks/features/clipboard/useGridClipboardImport.ts +++ b/packages/grid/x-data-grid-premium/src/hooks/features/clipboard/useGridClipboardImport.ts @@ -220,8 +220,8 @@ function defaultPasteResolver({ }) { const isSingleValuePasted = pastedData.length === 1 && pastedData[0].length === 1; - const cellSelectionModel = apiRef.current.getCellSelectionModel(); - const selectedCellsArray = apiRef.current.getSelectedCellsAsArray(); + const cellSelectionModel = apiRef.current.unstable_getCellSelectionModel(); + const selectedCellsArray = apiRef.current.unstable_getSelectedCellsAsArray(); if (cellSelectionModel && selectedCellsArray.length > 1) { Object.keys(cellSelectionModel).forEach((rowId, rowIndex) => { const rowDataArr = pastedData[isSingleValuePasted ? 0 : rowIndex];