Skip to content
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,10 @@ function DataGrid<R, SR, K extends Key>(
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
Expand All @@ -771,7 +771,7 @@ function DataGrid<R, SR, K extends Key>(
if (onSelectedCellChange && !samePosition) {
onSelectedCellChange({
rowIdx: position.rowIdx,
row,
row: isRowIdxWithinViewportBounds(position.rowIdx) ? rows[position.rowIdx] : undefined,
column: columns[position.idx]
Comment on lines 773 to 775
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can change the type to include row type similar to
https://github.com/adazzle/react-data-grid/blob/main/src/types.ts#L284

});
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export type CellKeyDownArgs<TRow, TSummaryRow = unknown> =

export interface CellSelectArgs<TRow, TSummaryRow = unknown> {
rowIdx: number;
row: TRow;
row: TRow | undefined;
column: CalculatedColumn<TRow, TSummaryRow>;
}

Expand Down
8 changes: 8 additions & 0 deletions test/browser/events.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
});
});

Expand Down