Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ const DataGridOverlayEditor: React.FunctionComponent<DataGridOverlayEditorProps>
event.preventDefault();
customMotion.current = [event.shiftKey ? -1 : 1, 0];
save = true;
} else {
// Only a motion key may schedule a commit. Any other key's timer
// could fire after a fast Enter has set the motion, committing
// with no value and marking the edit finished, so the commit
// that follows would be dropped.
return;
}

window.setTimeout(() => {
Expand Down
48 changes: 48 additions & 0 deletions packages/core/test/data-editor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,54 @@ describe("data-editor", () => {
expect(document.body.contains(overlay)).toBe(false);
});

test("Send edit when Enter follows another key before its timer fires", async () => {
const spy = vi.fn();
vi.useFakeTimers();
render(<DataEditor {...basicProps} onCellEdited={spy} />, {
wrapper: Context,
});
prep(false);

const canvas = screen.getByTestId("data-grid-canvas");
sendClick(canvas, {
clientX: 300, // Col B
clientY: 36 + 32 + 16, // Row 1 (0 indexed)
});

act(() => {
vi.runAllTimers();
});

fireEvent.keyDown(canvas, {
keyCode: 74,
key: "j",
});

act(() => {
vi.runAllTimers();
});

const overlay = screen.getByDisplayValue("j");

// A fast typist: the "k" keydown and Enter both land before any timer
// runs. The "k" timer must not commit on Enter's behalf with no value.
fireEvent.keyDown(overlay, {
keyCode: 75,
key: "k",
});
fireEvent.change(overlay, { target: { value: "jk" } });
fireEvent.keyDown(overlay, {
key: "Enter",
});

act(() => {
vi.runAllTimers();
});

expect(spy).toBeCalledWith([1, 1], expect.objectContaining({ data: "jk" }));
expect(document.body.contains(overlay)).toBe(false);
});

test("Send edit with click off", async () => {
const spy = vi.fn();
vi.useFakeTimers();
Expand Down