diff --git a/package.json b/package.json index 2e8d92d238..59d1a0970c 100644 --- a/package.json +++ b/package.json @@ -69,7 +69,7 @@ "@microsoft/api-extractor": "^7.23.0", "@rollup/plugin-babel": "^6.0.3", "@rollup/plugin-node-resolve": "^15.1.0", - "@tanstack/react-router": "^1.70.0", + "@tanstack/react-router": "1.82.1", "@tanstack/router-plugin": "^1.69.1", "@testing-library/dom": "^10.1.0", "@testing-library/react": "^16.0.0", diff --git a/src/DataGrid.tsx b/src/DataGrid.tsx index 593ed97154..9732d4bd63 100644 --- a/src/DataGrid.tsx +++ b/src/DataGrid.tsx @@ -755,10 +755,10 @@ function DataGrid( if (!isCellWithinSelectionBounds(position)) return; commitEditorChanges(); - const row = rows[position.rowIdx]; const samePosition = isSamePosition(selectedPosition, position); if (enableEditor && isCellEditable(position)) { + const row = rows[position.rowIdx]; setSelectedPosition({ ...position, mode: 'EDIT', row, originalRow: row }); } else if (samePosition) { // Avoid re-renders if the selected cell state is the same @@ -771,7 +771,7 @@ function DataGrid( if (onSelectedCellChange && !samePosition) { onSelectedCellChange({ rowIdx: position.rowIdx, - row, + row: isRowIdxWithinViewportBounds(position.rowIdx) ? rows[position.rowIdx] : undefined, column: columns[position.idx] }); } diff --git a/src/types.ts b/src/types.ts index 8eff5abe2b..519f6976b9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -196,7 +196,7 @@ export type CellKeyDownArgs = export interface CellSelectArgs { rowIdx: number; - row: TRow; + row: TRow | undefined; column: CalculatedColumn; } diff --git a/test/browser/events.test.tsx b/test/browser/events.test.tsx index 83cb0e0598..8bc17d3940 100644 --- a/test/browser/events.test.tsx +++ b/test/browser/events.test.tsx @@ -170,6 +170,14 @@ describe('Events', () => { rowIdx: 0 }); expect(onSelectedCellChange).toHaveBeenCalledTimes(5); + + // go to the header row + await userEvent.keyboard('{ArrowUp}'); + expect(onSelectedCellChange).toHaveBeenCalledWith({ + column: expect.objectContaining(columns[1]), + row: undefined, + rowIdx: -1 + }); }); });