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
16 changes: 16 additions & 0 deletions packages/core/src/cells/cell-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ interface BaseCellRenderer<T extends InnerGridCell> {
} & BaseGridMouseEventArgs
) => void;
readonly onDelete?: (cell: T) => T | undefined;

readonly onKeyDown?: (
args: {
readonly cell: T;
readonly bounds: Rectangle;
readonly location: Item;
readonly theme: FullTheme;
readonly preventDefault: () => void;
readonly key: string;
readonly keyCode: number;
readonly altKey: boolean;
readonly shiftKey: boolean;
readonly ctrlKey: boolean;
readonly metaKey: boolean;
}
) => T | undefined;
}

/** @category Renderers */
Expand Down
39 changes: 39 additions & 0 deletions packages/core/src/data-editor/data-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3498,6 +3498,45 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr

if (cancelled) return;

if (event.location !== undefined && event.bounds !== undefined && !overlayOpen) {
const [col, row] = event.location;
const cell = getMangledCellContent([col, row]);
const renderer = getCellRenderer(cell);

if (renderer?.onKeyDown !== undefined) {
let prevented = false;
const newVal = renderer.onKeyDown({
...event,
bounds: event.bounds,
Copy link
Copy Markdown
Author

@TigWork TigWork Oct 30, 2025

Choose a reason for hiding this comment

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

bounds is manually given because bounds is required prop in onKeyDown and TS doesn't understand that bounds is always defined from ...event.

cell,
location: [col - rowMarkerOffset, row],
Copy link

Copilot AI Jan 21, 2026

Choose a reason for hiding this comment

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

The coordinate transformation logic that adjusts for rowMarkerOffset is not covered by tests. Consider adding a test case that verifies the location parameter passed to onKeyDown is correctly adjusted when rowMarkers are enabled (e.g., rowMarkers="both"), similar to how other event handlers are tested with row markers in this file.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

theme: themeForCell(cell, event.location),
preventDefault: () => {
prevented = true;
},
});

if (prevented) {
event.preventDefault();
event.stopPropagation();
}

if (
newVal !== undefined &&
!isInnerOnlyCell(newVal) &&
isEditableGridCell(newVal) &&
!isInnerOnlyCell(cell) &&
isEditableGridCell(cell) &&
cell.readonly !== true
) {
mangledOnCellsEdited([{ location: event.location, value: newVal }]);
gridRef.current?.damage([{ cell: event.location }]);
}

if (prevented) return;
}
}

if (handleFixedKeybindings(event)) return;

if (gridSelection.current === undefined) return;
Expand Down
Loading