Skip to content

Commit 42fb515

Browse files
authored
fix: call onCellActivated on typing (#1055)
1 parent 72b9ee8 commit 42fb515

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

packages/core/API.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Most data grids will want to set the majority of these props one way or another.
156156
| [maxColumnAutoWidth](#maxcolumnwidth) | Sets the maximum width a column can be auto-sized to. |
157157
| [maxColumnWidth](#maxcolumnwidth) | Sets the maximum width the user can resize a column to. |
158158
| [minColumnWidth](#maxcolumnwidth) | Sets the minimum width the user can resize a column to. |
159-
| [onCellActivated](#oncellactivated) | Emitted when a cell is activated, by pressing Enter, Space or double clicking it. |
159+
| [onCellActivated](#oncellactivated) | Emitted when a cell is activated, such as by pressing Enter, Space, double clicking, or typing. |
160160
| [onCellClicked](#oncellclicked) | Emitted when a cell is clicked. |
161161
| [onCellContextMenu](#oncellcontextmenu) | Emitted when a cell should show a context menu. Usually right click. |
162162
| [onColumnMoved](#oncolumnmoved) | Emitted when a column has been dragged to a new location. |
@@ -1124,7 +1124,7 @@ onCellClicked?: (cell: Item) => void;
11241124
onCellActivated?: (cell: Item) => void;
11251125
```
11261126

1127-
`onCellActivated` is called whenever the user double clicks, taps Enter, or taps Space on a cell in the grid.
1127+
`onCellActivated` is called whenever the user double clicks, presses Enter or Space, or begins typing with a cell selected.
11281128

11291129
---
11301130

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,6 +3379,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
33793379
) {
33803380
return;
33813381
}
3382+
onCellActivated?.([col - rowMarkerOffset, row]);
33823383
reselect(event.bounds, true, event.key);
33833384
event.stopPropagation();
33843385
event.preventDefault();
@@ -3393,6 +3394,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
33933394
rowMarkerOffset,
33943395
rows,
33953396
showTrailingBlankRow,
3397+
onCellActivated,
33963398
reselect,
33973399
]
33983400
);

packages/core/src/docs/examples/cell-activated-event.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export const CellActivatedEvent: React.VFC<Pick<DataEditorCoreProps, "cellActiva
5555
description={
5656
<>
5757
<Description>
58-
When you tap <KeyName>Enter</KeyName>, <KeyName>Space</KeyName> or double click a cell, that
59-
cell is activated. You can track this with <PropName>onCellActivated</PropName>.
58+
When you tap <KeyName>Enter</KeyName>, <KeyName>Space</KeyName>, start typing, or double click a cell,
59+
that cell is activated. You can track this with <PropName>onCellActivated</PropName>.
6060
</Description>
6161
<MoreInfo>
6262
Last activated cell:{" "}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,33 @@ describe("data-editor", () => {
665665
expect(spy).toHaveBeenCalledWith([1, 1]);
666666
});
667667

668+
test("Emits activated event when typing", async () => {
669+
const spy = vi.fn();
670+
671+
vi.useFakeTimers();
672+
render(<DataEditor {...basicProps} onCellActivated={spy} />, {
673+
wrapper: Context,
674+
});
675+
prep(false);
676+
677+
const canvas = screen.getByTestId("data-grid-canvas");
678+
sendClick(canvas, {
679+
clientX: 300, // Col B
680+
clientY: 36 + 32 + 16, // Row 1 (0 indexed)
681+
});
682+
683+
fireEvent.keyDown(canvas, {
684+
key: "A",
685+
});
686+
687+
act(() => {
688+
vi.runAllTimers();
689+
});
690+
691+
expect(spy).toHaveBeenCalled();
692+
expect(spy).toHaveBeenCalledWith([1, 1]);
693+
});
694+
668695
test("keyDown and keyUp events include the cell location", async () => {
669696
let keyDownEvent: GridKeyEventArgs | undefined;
670697
let keyUpEvent: GridKeyEventArgs | undefined;

0 commit comments

Comments
 (0)