Skip to content

Commit

Permalink
feat: create & pass editCell function to onClick
Browse files Browse the repository at this point in the history
  • Loading branch information
Aram Vardanyan committed Apr 27, 2023
1 parent bda0bdd commit 0684fef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/core/src/data-editor/data-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
bounds: args.bounds,
theme: themeForCell(markerCell, args.location),
preventDefault: () => undefined,
editCell: () => editCell(args)
}) as MarkerCell | undefined;
if (postClick === undefined || postClick.checked === markerCell.checked) return;
}
Expand Down Expand Up @@ -1972,6 +1973,27 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr

const [scrollDir, setScrollDir] = React.useState<GridMouseEventArgs["scrollEdge"]>();

const editCell = React.useCallback(
async (args:GridMouseCellEventArgs): Promise<void> => {

const [col, row] = args.location
const cell = getCellContentRef.current([col - rowMarkerOffset, row]);

if (cell.allowOverlay && isReadWriteCell(cell) && cell.readonly !== true) {
setOverlaySimple({
target: args.bounds,
content: cell,
initialValue: undefined,
cell: [col, row],
highlight: true,
forceEditMode: true,
});
}

},
[rowMarkerOffset, setOverlaySimple]
);

const onMouseUp = React.useCallback(
(args: GridMouseEventArgs, isOutside: boolean) => {
const mouse = mouseState;
Expand Down Expand Up @@ -2011,6 +2033,7 @@ const DataEditorImpl: React.ForwardRefRenderFunction<DataEditorRef, DataEditorPr
bounds: a.bounds,
theme: themeForCell(c, args.location),
preventDefault,
editCell: () => editCell(a),
});
if (newVal !== undefined && !isInnerOnlyCell(newVal) && isEditableGridCell(newVal)) {
mangledOnCellsEdited([{ location: a.location, value: newVal }]);
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/data-grid/cells/cell-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ interface BaseCellRenderer<T extends InnerGridCell> {
readonly posY: number;
readonly bounds: Rectangle;
readonly theme: Theme;
readonly editCell: () => void,
readonly preventDefault: () => void;
} & BaseGridMouseEventArgs
) => T | undefined;
Expand Down

0 comments on commit 0684fef

Please sign in to comment.