Skip to content

Commit f22fd7e

Browse files
author
tyengibaryan
committed
fix: pr comments
1 parent 2134250 commit f22fd7e

2 files changed

Lines changed: 70 additions & 5 deletions

File tree

packages/core/src/data-editor/data-editor.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3521,7 +3521,13 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
35213521
event.stopPropagation();
35223522
}
35233523

3524-
if (newVal !== undefined && !isInnerOnlyCell(newVal) && isEditableGridCell(newVal) && newVal.readonly !== true) {
3524+
if (
3525+
newVal !== undefined &&
3526+
!isInnerOnlyCell(newVal) &&
3527+
isEditableGridCell(newVal) &&
3528+
isEditableGridCell(cell) &&
3529+
cell.readonly !== true
3530+
) {
35253531
mangledOnCellsEdited([{ location: event.location, value: newVal }]);
35263532
gridRef.current?.damage([{ cell: event.location }]);
35273533
}

packages/core/test/data-editor.test.tsx

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5065,8 +5065,8 @@ describe("data-editor", () => {
50655065
const mockStopPropagation = vi.fn();
50665066

50675067
const evt = createEvent.keyDown(canvas, { key: 'ArrowDown', code: 'ArrowDown' });
5068-
evt.preventDefault = mockPreventDefault
5069-
evt.stopPropagation = mockStopPropagation
5068+
evt.preventDefault = mockPreventDefault;
5069+
evt.stopPropagation = mockStopPropagation;
50705070
fireEvent(canvas, evt);
50715071

50725072
// Renderer's onKeyDown should have been called
@@ -5405,8 +5405,8 @@ describe("data-editor", () => {
54055405
const mockStopPropagation = vi.fn();
54065406

54075407
const evt = createEvent.keyDown(canvas, { key: 'x' });
5408-
evt.preventDefault = mockPreventDefault
5409-
evt.stopPropagation = mockStopPropagation
5408+
evt.preventDefault = mockPreventDefault;
5409+
evt.stopPropagation = mockStopPropagation;
54105410
fireEvent(canvas, evt);
54115411

54125412
act(() => {
@@ -5418,4 +5418,63 @@ describe("data-editor", () => {
54185418
expect(mockPreventDefault).toHaveBeenCalled();
54195419
expect(mockStopPropagation).toHaveBeenCalled();
54205420
});
5421+
5422+
test("Cell renderer onKeyDown location should be adjusted when row markers are enabled", async () => {
5423+
const mockOnKeyDown = vi.fn();
5424+
const customRenderer = {
5425+
kind: GridCellKind.Custom,
5426+
isMatch: (c: GridCell): c is CustomCell => c.kind === GridCellKind.Custom,
5427+
draw: () => true,
5428+
onKeyDown: mockOnKeyDown,
5429+
};
5430+
5431+
vi.useFakeTimers();
5432+
render(
5433+
<DataEditor
5434+
{...basicProps}
5435+
rowMarkers="both"
5436+
customRenderers={[customRenderer]}
5437+
getCellContent={() => {
5438+
return {
5439+
kind: GridCellKind.Custom,
5440+
allowOverlay: false,
5441+
copyData: "",
5442+
data: { value: "custom-cell" },
5443+
};
5444+
}}
5445+
/>,
5446+
{ wrapper: Context }
5447+
);
5448+
prep(false);
5449+
5450+
const canvas = screen.getByTestId("data-grid-canvas");
5451+
5452+
// Click on cell at visual position [2, 1] (which is col B when row markers are enabled)
5453+
// With row markers, column 0 is the row marker, so visual col 2 is data col 1
5454+
sendClick(canvas, {
5455+
clientX: 320, // Adjusted for row marker width
5456+
clientY: 36 + 32 + 16, // Row 1
5457+
});
5458+
5459+
act(() => {
5460+
vi.runAllTimers();
5461+
});
5462+
5463+
// Press a key
5464+
fireEvent.keyDown(canvas, {
5465+
key: "a",
5466+
keyCode: 65,
5467+
});
5468+
5469+
// The location should be adjusted: internal grid col 2 minus rowMarkerOffset (1) = [1, 1]
5470+
expect(mockOnKeyDown).toHaveBeenCalledWith(
5471+
expect.objectContaining({
5472+
cell: expect.objectContaining({
5473+
kind: GridCellKind.Custom,
5474+
}),
5475+
location: [1, 1], // Adjusted for row marker offset
5476+
key: "a",
5477+
})
5478+
);
5479+
});
54215480
});

0 commit comments

Comments
 (0)