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
32 changes: 32 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,38 @@ 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
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],
theme: themeForCell(cell, event.location),
preventDefault: () => {
prevented = true;
},
});

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

if (newVal !== undefined && !isInnerOnlyCell(newVal) && isEditableGridCell(newVal) && newVal.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