Skip to content

Commit

Permalink
Merge pull request #10 from vabrahamyanadobe/feat/add-cell-location-o…
Browse files Browse the repository at this point in the history
…n-keydown-event-wf

Feat/add cell location on keydown event wf
  • Loading branch information
aramvr committed Mar 29, 2023
2 parents de2c702 + 01b33bf commit 9b70852
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/core/src/data-editor/data-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3409,6 +3409,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
shiftKey: false,
altKey: false,
rawEvent: undefined,
location: {},
});
break;
case "fill-right":
Expand All @@ -3424,6 +3425,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
shiftKey: false,
altKey: false,
rawEvent: undefined,
location: {},
});
break;
case "fill-down":
Expand All @@ -3439,6 +3441,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
shiftKey: false,
altKey: false,
rawEvent: undefined,
location: {},
});
break;
case "copy":
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/data-grid/data-grid-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export interface GridKeyEventArgs {
readonly stopPropagation: () => void;
readonly preventDefault: () => void;
readonly rawEvent: React.KeyboardEvent<HTMLElement> | undefined;
readonly location: { col?: number; row?: number };
}

interface DragHandler {
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/data-grid/data-grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1135,8 +1135,11 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
if (canvas === null) return;

let bounds: Rectangle | undefined;
const location: { col?: number; row?: number } = {};
if (selection.current !== undefined) {
bounds = getBoundsForItem(canvas, selection.current.cell[0], selection.current.cell[1]);
location.col = selection.current.cell[0];
location.row = selection.current.cell[1];
}

onKeyDown?.({
Expand All @@ -1151,6 +1154,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
key: event.key,
keyCode: event.keyCode,
rawEvent: event,
location,
});
},
[onKeyDown, selection, getBoundsForItem]
Expand All @@ -1162,8 +1166,11 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
if (canvas === null) return;

let bounds: Rectangle | undefined;
const location: { col?: number; row?: number } = {};
if (selection.current !== undefined) {
bounds = getBoundsForItem(canvas, selection.current.cell[0], selection.current.cell[1]);
location.col = selection.current.cell[0];
location.row = selection.current.cell[1];
}

onKeyUp?.({
Expand All @@ -1178,6 +1185,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
key: event.key,
keyCode: event.keyCode,
rawEvent: event,
location,
});
},
[onKeyUp, selection, getBoundsForItem]
Expand Down Expand Up @@ -1550,6 +1558,7 @@ const DataGrid: React.ForwardRefRenderFunction<DataGridRef, DataGridProps> = (p,
shiftKey: false,
altKey: false,
rawEvent: undefined,
location: { col, row },
});
}}
onFocusCapture={e => {
Expand Down

0 comments on commit 9b70852

Please sign in to comment.