diff --git a/src/DataGrid.tsx b/src/DataGrid.tsx index 7da949062d..b2352511b7 100644 --- a/src/DataGrid.tsx +++ b/src/DataGrid.tsx @@ -543,11 +543,11 @@ function DataGrid( const cKey = 67; const vKey = 86; if (keyCode === cKey) { - handleCopy(); + handleCopy(event); return; } if (keyCode === vKey) { - handlePaste(); + handlePaste(event); return; } } @@ -599,15 +599,15 @@ function DataGrid( updateRow(columns[selectedPosition.idx], selectedPosition.rowIdx, selectedPosition.row); } - function handleCopy() { + function handleCopy(event: KeyboardEvent) { const { idx, rowIdx } = selectedPosition; const sourceRow = rows[rowIdx]; const sourceColumnKey = columns[idx].key; setCopiedCell({ row: sourceRow, columnKey: sourceColumnKey }); - onCopy?.({ sourceRow, sourceColumnKey }); + onCopy?.({ event, sourceRow, sourceColumnKey }); } - function handlePaste() { + function handlePaste(event: KeyboardEvent) { if (!onPaste || !onRowsChange || copiedCell === null || !isCellEditable(selectedPosition)) { return; } @@ -617,6 +617,7 @@ function DataGrid( const targetRow = rows[rowIdx]; const updatedTargetRow = onPaste({ + event, sourceRow: copiedCell.row, sourceColumnKey: copiedCell.columnKey, targetRow, diff --git a/src/types.ts b/src/types.ts index f3b52c2f38..ddb331714c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -212,11 +212,13 @@ export interface FillEvent { } export interface CopyEvent { + event: React.KeyboardEvent; sourceColumnKey: string; sourceRow: TRow; } export interface PasteEvent { + event: React.KeyboardEvent; sourceColumnKey: string; sourceRow: TRow; targetColumnKey: string;